Adding Floating-Point Decimals for Fun and Profit

(blog.vero.site)

15 points | by ibobev 1 day ago

1 comments

  • amelius 29 minutes ago
    > Many people know that you shouldn’t do decimal calculations, such as those involving U.S. dollars and cents, with the floating-point numbers in most programming languages. This is because decimal numbers can’t be expressed exactly as such floating-point numbers, so you will encounter rounding errors.

    Why not, rounding to the nearest cent is going to be much less precise for any realistic amount of dollars when using 64 bit floats (the type of float Javascript uses in every browser).