algorithm - How to round currency values -


i have several ways solve this, interested in whether there better solution problem. please respond pure numeric algorithm. string manipulation not acceptable. looking elegant , efficient solution.

given currency value (ie $251.03), split value 2 half , round 2 decimal places. key first half should round , second should round down. outcome in scenario should $125.52 , $125.51.

divide two, round 2 d.p. (in c# decimal.round(value, 2)), subtract rounded value original, , sort them using if. library may support control on rounding can save if - c# can using 3-parameter overload of decimal.round.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -