Advertisement
Guest User

DoubleExtentions

a guest
Aug 14th, 2016
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.57 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3.  
  4. namespace ConsoleApp.ExtMethods
  5. {
  6.     public static class DoubleExtentions
  7.     {
  8.         public static int IntPart(this double value)
  9.         {
  10.             return (int)Math.Truncate(value);
  11.         }
  12.  
  13.         public static int FractPart(this double value)
  14.         {
  15.             var str = value.ToString();
  16.             int sepIndex = str.LastIndexOf(Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencyDecimalSeparator);
  17.             return (sepIndex != -1) ? int.Parse(str.Substring(sepIndex + 1)) : 0;
  18.         }
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement