Hacker Newsnew | comments | show | ask | jobs | submit login

Don't do that. All of the major database players have built in fixed point decimal types with user specified precision. You'd be reinventing the wheel.

As far as doing mathematical operations on the values, if you're using double precision floats, you have 15 digits of precision before you run into problems. In most situations, you're going to be dealing with values considerably less than 10 trillion dollars, so that will be totally sufficient. That's good news if you're using a language like JavaScript or Lua, where there is no built in integer type.




I've found (having written too much physics code for my own good) that floats give you 0 digits of precision - I ask for 4.0 and it gives me 3.999999999998 .. ;)

The solution is, of course, to use rational numbers ( http://gmplib.org/ ) if you have time to debug why GMP doesn't compile on your processor.

-----




Guidelines | FAQ | Support | API | Lists | Bookmarklet | DMCA | Y Combinator | Apply | Contact

Search: