Java BigDecimal longValue()精度丢失,自动变整数

 现象:
 

原因:

 

 /**  * Rounding mode to round towards zero.  Never increments the digit  * prior to a discarded fraction (i.e., truncates).  Note that this  * rounding mode never increases the magnitude of the calculated value.  */

 

/**

*舍入模式向零舍入。从不递增数字

*在丢弃的部分之前(即截断)。请注意

*舍入模式永远不会增加计算值的大小。

*/



public final static int ROUND_DOWN =         1;

其实 Long 本身就是没保留小数 ,硬说是精度丢失嘛,也可这么说,其实你不转long就好了。

.doubleValue():

 

猜你喜欢

转载自blog.csdn.net/qq_35387940/article/details/129929465