BigDecimal
- 用于解决浮点型运算时,出现结果失真的问题。
例如:
package bigDecimal; /** * @Auther lmy * @date 2024-03-31 1:27 * @Description This is description of code */ public class Testmain { public static void main(String[] args) { //浮点型运算时,直接+-*/可能会出现运算结果失真 System.out.println(0.1 + 0.2); System.out.println(1.0 - 0.32); System.out.println(1.015 * 100); System.out.println(1.301 / 100); } }
运行结果:
解决:使用BigDecimal类