Tech
How to Represent Money in Software
Quick Answer: Never use floating-point numbers to represent money in software. Because floating-point math cannot perfectly represent base-10 decimals, it introduces microscopic inaccuracies that compound over time. I recommend using either a dedicated arbitrary-precision decimal library or storing currency as integers representing micro-units to guarantee exact calculations.
If I ask you how to represent £1.29 in code, your naive first instinct might be to just drop it into a floating-point...
Read the full discussion on Dev.to
This article was aggregated from Dev.to. Click to join the conversation.
View on Dev.to