‹ BackHN Continuity

Thread

Adding Floating-Point Decimals for Fun and Profit

62 points · 35 comments · ibobev

  1. jgalt212 · · focus · HN ↗
    > 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.

    Decimals or pennies, you still have rounding errors. For example, if your contract is $100 / year. You will get the full $100 if you bill yearly, quarterly, or semi-annually. But if you bill monthly, no matter if you deal in pennies or fractional dollars, the sum total of your invoices for the year will be less than $100.

    1. nitwit005 · · focus · HN ↗
      Usually the contract itself specifies how that should work. You often see a schedule of payments, and how dealing with early cancelation should work.
Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.