c# - How truncate a decimal part? -
c# - How truncate a decimal part? -
i'm trying truncate decimal part.
i mean create function this.
1/9 ~ 0.11111111111111
so, if in function set wants pick 5 decimals, must returns 0.11111
i doing using strings, guess not idea. possible using math operations?
you can utilize
math.truncate
http://msdn.microsoft.com/en-us/library/7d101hyf.aspx
edit: version of suitable method (though gary has shared 1 below)
public static double truncate(double number, int digits) { double conversionfactor = (math.pow(10.0, digits)); homecoming math.truncate(number * conversionfactor) / conversionfactor; }
c# algorithm class
Comments
Post a Comment