Use the Float type to receive the String type accuracy exception

Many input boxes involving amounts of money are used in the project. The oralce database is generally set to number (18, 2) to meet the storage requirements of most projects.
However, when the background uses the Float type to receive, there will be accuracy errors, such as 29999999 entered at the front desk , After receiving with Float in the background, it will automatically +1 and convert to 30000000, and the automatic conversion of Float uses scientific notation, which causes the accuracy to be wrong. Normally, it is correct to pass as many single digits as required. The decimal point is generally rounded.
The solution is to use the BigDecimal type to receive when receiving in the background. When saving directly, it can be stored in the library normally without loss of accuracy. When calculating the accumulation, use the BigDecimal.add method.

Guess you like

Origin blog.csdn.net/wujian_csdn_csdn/article/details/105835162