c# - rounding decimal to special number of digits -
i need create function rounds decimal numbers this:
round("$32.95", 0) -> $33 round("85.86%", 1) -> 86.9%
where first parameter string , second parameter number of decimal points required
i using math.round converting 85.9
an algorithm can use (i don't know c#):
- get 10-to-the-power(number-of-significant-digits) (=p10)
- multiply decimal-number p10
- add: 0.5
- divide integer-portion of sum (p10) - answer rounded number
Comments
Post a Comment