当前位置:网站首页>[daily record] - bug encountered during BigDecimal Division
[daily record] - bug encountered during BigDecimal Division
2022-06-25 17:47:00 【Simplememory】
Recently in the project test environment , Meet such a problem ; Check the log , The error information is as follows :
*Exception in thread "main" java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result. at java.math.BigDecimal.divide(BigDecimal.java:1693)
*
Find... By positioning : Is used in code BigDecimal Of divide Method .
The inspection found that : This is because in the BigDecimal There is no error to divide the report , So we need to go to divide The function passes in parameter settings to keep several decimal places .
「 Problem reduction 」
Here is a test code to demonstrate the scenario without division .
BigDecimal a = new BigDecimal(1);
BigDecimal b = new BigDecimal(3);
BigDecimal result = a.divide(b);
System.out.println("result = " + result);

「 terms of settlement 」
We treat it divide Method , Set the number of decimal places passed in by the parameter , And the specific rounding mode .
// Keep two decimal places 、 rounding
BigDecimal result = a.divide(b,2,BigDecimal.ROUND_HALF_UP);
边栏推荐
- ACY100油烟浓度在线监控仪针对饮食业厨房油烟排放
- CGI connects to database through ODBC
- How Jerry used to output a clock source to the outside world [chapter]
- Swagger implements background interface automation document
- 沁恒CH583 USB 自定义HID调试记录
- conda安装的py3.6和py3.7
- Intelligent dialog 01 redis installation
- Operating steps for installing CUDA in win10 (continuous improvement)
- 力扣每日一题-第27天-561.数组拆分Ⅰ
- 喜报|海泰方圆通过CMMI-3资质认证,研发能力获国际认可
猜你喜欢

Mobile heterogeneous computing technology - GPU OpenCL programming (basic)

College Students' hot summer exchange, Rog star product phantom 16 flipped version / phantom 13 / phantom x appointment
![[tips] how to quickly start a new position for a new software testing engineer](/img/88/5c002f492db56c646cbfd1ee98cd5b.png)
[tips] how to quickly start a new position for a new software testing engineer

Unity technical manual - lifecycle rotation rotationoverlifetime speed rotation rotationbyspeed external forces

win10安装cuda的操作步骤(不断完美中)

杰理之增加加密文件播放功能【篇】

相同wifi下,笔记本连接台式机上的虚拟机
![[efficiency] another note artifact is open source!](/img/f7/bcea89deaac3e6a6716df7826c1078.jpg)
[efficiency] another note artifact is open source!

配电室环境的分布式远程管理
![[matlab] data interpolation](/img/b8/d7e1a5f7c6f56c8312a1fb5d517ac6.png)
[matlab] data interpolation
随机推荐
使用DiskGenius拓展系统盘C盘的容量
【日常记录】——对BigDecimal除法运算时遇到的Bug
用连续自然数之和来表达整数
Time series analysis of data mining [easy to understand]
[matlab] numerical calculus and equation solving
Encryption trend: Fashion advances to the meta universe
【UVM实战 ===> Episode_1 】~ MCDF设计更新、AMBA标准接口、UVM验证环境更新
匯編語言(5)寄存器(內存訪問)
Getting started with kotlin (20) several common dialog boxes
解决nvprof 报错ERR_NVGPUCTRPERM - The user does not have permission to profile on the target device.
Swagger implements background interface automation document
汇编语言(6)使用JCC指令构造分支与循环
[matlab] data statistical analysis
TLV decoding
Jerry's addition of encrypted file playback function [chapter]
20 provinces and cities announce the road map of the meta universe
golang list to string
Acy100 oil fume concentration online monitor for kitchen oil fume emission in catering industry
New characteristics of cultural consumption in the era of digital economy
怎么判断自己是否适合转行软件测试