round and round we go

    Date: 06/03/05 (Asp Dot Net)    Keywords: no keywords

    an interesting thing that i noted while working on an app the other day.. i had to round up some currency to the nearest nickel and found some peculiar thing with .NET's Math.Round.. it wasn't exactly doing the same sort of arithmetic rounding that we learn as kids (with an upwards bias), where you would round up if the trailing digit is >=5 and round down if the trailing digit is <5. i ended up writing my own customized rounding function using a variant of an assymetric arithmetic rounding algorithm that rounds up to the nearest 0.05.

    so, after some poking around and research, it seems like .NET is using an algorithm called Banker's rounding.. which at 5, it rounds to the nearest even number. pretty sleazy, imo. :) anyway, point being, if you're working on some currency related app, you may want to note the subtle yet possibly drastic possible arithmetic inaccuracy ala. the movie "office space" if you're not privy to the type of rounding algorithm a particular language is using.

    here's a good article if you're interested in looking into the types of rounding algos. available and used.
    http://support.microsoft.com/?kbid=196652

    xposted in my journal and '[info]'csharp

    Source: http://www.livejournal.com/community/aspdotnet/34746.html

« LEFT function ntext data type || .Net Framework 2 host »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home