Java Numeric Types

Choosing and using Java's numeric types correctly: binary floating-point limits for exact decimal amounts, BigDecimal construction, scale, rounding and the equals/compareTo split, integer overflow and the exact-arithmetic methods, primitives versus boxed types, the boxed-value caching that makes == appear to work for some values, unboxing NPEs, boxing cost in bulk paths, and what happens to a numeric value when it crosses JSON, a database column or a JavaScript client. Use when money or any exact quantity is held in double or float, when new BigDecimal(double) appears, when divide() has no rounding mode, when BigDecimal values are compared with equals, when boxed types are compared with ==, when a nullable Integer is unboxed, when arithmetic on ids, timestamps or sizes could overflow, or when large longs are serialised to a browser. Does not cover date and time types, string formatting and parsing (java-strings-and-text), or measuring allocation (allocation-profiling).

robsonkades 666c46b 4 files · 33.1 KB Updated

File contents

robsonkades/agent-skills/tree/main/skills/java-numeric-types commit 666c46b696

Frequently asked questions

npx skillmds@latest add robsonkades/java-numeric-types