java - BigDecimal toEngineeringString 不起作用

标签 java android

我想使用toEngineeringString(),但它不起作用:

Log.v("smslms",BigDecimal.valueOf(1_000_0000_000_000_000L).toEngineeringString());`

输出:

09-11 16:26:12.221  18492-18492/skarwild.game V/smslms﹕ 10000000000000000

最佳答案

它的行为与 documented 完全相同:

Returns a string that represents the BigDecimal as described in the toString() method, except that if exponential notation is used, the power of ten is adjusted to be a multiple of three (engineering notation) such that the integer part of nonzero values will be in the range 1 through 999.

现在toString()指定:

A standard canonical string form of the BigDecimal is created as though by the following steps: first, the absolute value of the unscaled value of the BigDecimal is converted to a string in base ten using the characters '0' through '9' with no leading zeros (except if its value is zero, in which case a single '0' character is used).

Next, an adjusted exponent is calculated; this is the negated scale, plus the number of characters in the converted unscaled value, less one. That is, -scale+(ulength-1), where ulength is the length of the absolute value of the unscaled value in decimal digits (its precision).

If the scale is greater than or equal to zero and the adjusted exponent is greater than or equal to -6, the number will be converted to a character form without using exponential notation.

在我们的例子中,标度为 0,因此调整后的指数为 16(或类似值)。因此,该值将转换为字符形式,而不使用指数表示法。

关于java - BigDecimal toEngineeringString 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32525925/

相关文章:

java - 循环没有为字符串分配正确的值

java - 其他方法的一维阵列频率计数器

java - 错误 "ResultSet closed"

java - 使用 Fragments 进行 Android 搜索

android - 在 Android 中使用 Wowza Server 获取实时 ip 地址的实时视频广播

java - Trig AlertDialog 我们选中复选框

java - 表存在时出现SQLException

java - PlayN声音: Requested buffer too large

android - Robotium 如何使用转换等后台服务进行测试?

java - 注释值不是允许的类型 rrror : illegal initializer for int