Menu

Money in Code: Integer Cents vs Decimal Types
πŸ“°

Money in Code: Integer Cents vs Decimal Types

DEV Community: javaΒ·t.laboΒ·about 13 hours ago
#WefVn9fq
#devtojava#devto#dev#decimal#currency
Reading 0:00
15s threshold

Series: Numbers & Money lecture 4/6 (intermediate). For developers who have seen rounding go wrong (lecture 3) and now need to store prices, total a cart, split a bill or convert currencies without a one-cent ticket. By the end you will know when to use integer cents and when a decimal type, the traps each decimal type hides in Python, Java, C#, PHP and Swift, and an allocation function that never loses a cent.

Money bugs are rarely dramatic. They are a refund that is one cent short, a CSV export that does not match the payment provider, or a currency field that silently became a float in some layer. This lecture is for the person who has to fix that, and who wants the rules backed by output rather than opinion.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.