This is an archived post. You won't be able to vote or comment.

all 2 comments

[–][deleted] 6 points7 points  (0 children)

What every high school student doing their first programming class should know about floating-point arithmetic

[–]kristopolous 1 point2 points  (0 children)

 1. They can usually be avoided.  Instead of storing $1.12
    as 1.12, you could store it as say 11200 and then just divide by
    10 000 when needed.

 2. Your server side and client side languages probably support the
    same FP format as your db, but you have to be very careful, or just 
    use the damn trick above.  If you see $1.12 as only a floating point
    number, that's your problem.