You are not logged in. You can browse but not post. Login or Register by clicking 'Login or Register' at the top-right of this page. For more information on Statalist, see the FAQ.
You want to record data as multiples of 0.01. But most multiples of 0.01 don't have exact binary representations, which is what computers use. Enormous skill and ingenuity go into relieving users of needing to worry, or even to think, about that, but sometimes it bites. Off the top of my head, I know that numbers ending in .50 do have exact binary representations, and numbers ending in .25 or .75, but that's it I think.
What you can do, and this may be enough for your purposes, is to insist on a display format such as %3.2f.
Off the top of my head, I know that numbers ending in .50 do have exact binary representations, and numbers ending in .25 or .75, but that's it I think.
That's correct. The generalization is that an exact representation in base B is possible for fraction M/N if and only if all of the prime factors of N divide B. When B is 2, as in binary computers, this means that N must be a power of 2. Going out to two decimal places, only 1/4, 2/4, and 3/4 meet this criterion--hence Nick's result. The same generalization implies that an exact representation in base 10 is possible only for fractions whose denominators are products of powers of 2 and powers of 5.
In a concrete and common case, currency calculations based on large unit/100 small units are best done as integer calculations and then presented as you wish.
Comment