我在操作 Double 值时遇到问题。
我们来吧,
Double d = new Double(123456789987654321123456789d);
System.out.println(d);
输出是:
1.2345678912345678E35
但我想要,
123456789987654321123456789
不带任何符号的完整数字。
我已经尝试使用 BigDecimal
、BigInteger
等进行所有排列。
注意:我想填充为 JSON,因此请不要仅建议 print
语句。
我已经读过:
最佳答案
试试这个BigDecimal::toPlainString
:
BigDecimal d = new BigDecimal("123456789987654321123456789");
String result = d.toPlainString();
d 的输出是:
123456789987654321123456789
<小时/>
要填充到 JSon 有很多方法,我不确定你到底想要什么,但这也许可以帮助你How to create JSON Object using String?:
BigDecimal d = new BigDecimal("123456789987654321123456789");
JSONObject myObject = new JSONObject();
myObject.put("number", d.toPlainString());
关于java - 如何从 double 中删除科学记数法以获得最长的 double 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47809586/