3 ms·
I'm guessing that he's saying binary doesn't represent all numbers properly so if you need it to be absolutely accurate, you need to have a custom data type. M
by richardw 18y ago
I'm guessing that he's saying binary doesn't represent all numbers properly so if you need it to be absolutely accurate, you need to have a custom data type. Making it picoseconds doesn't help.
Same problem with money - it's a very bad idea to use floats etc for money.
- mark-t 18y agoI covered that. There is no "absolutely accurate" in a finite number of bits, no matter what data type you use. In N bits, you can't store more than 2^N distinct numbers, and there happen to be a lot more than 2^N distinct numbers, even between 0 and 1. You have to choose your margin for error and be prepared to live with it (or use a variable width format).
- pistoriusp 18y agoIs a solution for money to convert everything to cents?
- richardw 18y agoThat can work, for some tasks. Lookit this article for more info: http://www2.hursley.ibm.com/decimal/decifaq1.html#inexact http://www2.hursley.ibm.com/decimal/decifaq1.html#inexact Many languages have built-in formats for decimal data, so unless you have a really good reason (space/speed), just use those.