Posted by Andy Hassall on 12/06/05 03:01
On Mon, 05 Dec 2005 19:41:25 +0000, Philip Ronan <invalid@invalid.invalid>
wrote:
>"Andy Hassall" wrote:
>
>> You appear to be working with monetary values from the names in your original
>> post. You shouldn't use floating point numbers for money; use integers,
>> multiplied up to the minor currency. So £1.50 = 150.
>
>There might be a good reason for using floats. For example, all your sales
>tax calculations will be rounded down if you use integers.
Then you can multiply up to the number of decimal places required by your tax
authority and apply their rounding rules (up or down) - more deterministic than
having small but unpredictable amounts of money being lost or gained due to
non-exact float representations. Depending on how many decimals you pick, the
32-bit limits on integers (31 bits for signed) could then become a problem for
large transactions or monthly/yearly totals.
--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
[Back to original message]
|