在我的代码中,我想插入数据库而不进行任何舍入或取幂..但是当我使用sop为2.631578947368421E-7时,它会在我的java代码中转换
以下是我使用的代码:
BigDecimal a =new BigDecimal(0.0000002631578947368421052631578947368421052632,MathContext.DECIMAL64);
System.out.println(a);
Run Code Online (Sandbox Code Playgroud)
我只是希望它保持原样,因为我想做一些计算.
请给我一个合适的解决方案.
使用String构造大小数,否则输入的常量在作为参数传递给构造函数之前会被舍入BigDecimal.
所以写这样的东西:
BigDecimal a =new BigDecimal("0.0000002631578947368421052631578947368421052632");
System.out.println(a.toPlainString());
Run Code Online (Sandbox Code Playgroud)
一切都应该奏效.
编辑:您还应该删除构造函数的第二个参数作为
static MathContext.DECIMAL64手段:A MathContext object with a precision setting matching the IEEE 754R Decimal64 format, 16 digits, and a rounding mode of HALF_EVEN, the IEEE 754R default.
EDIT2:a.toPlainString()打印时也使用不使用科学记数法.
| 归档时间: |
|
| 查看次数: |
1501 次 |
| 最近记录: |