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

Popular posts from this blog

How do you change vbulletin's home page to the forums instead of the default (CMS or Activity Stream)? -

c++ - Troubles when compiling phash program -