Double.tostring()
是使用当前本地的小数分隔符还是为所有语言环境和实现固定的东西(即:点“.”)?
最佳答案
Double.toString()
方法代码:
public String toString() {
return toString(value);
}
调用这个静态方法:
public static String toString(double d) {
return FloatingDecimal.toJavaFormatString(d);
}
它的javadoc是指方法的用例,都是指.
字符作为整数和小数部分之间的分隔符:
If m is zero, it is represented by the characters "0.0"; thus, negative zero produces the result "-0.0" and positive zero produces the result "0.0".
If m is greater than or equal to 10-3 but less than 107, then it is represented as the integer part of m, in decimal form with no leading zeroes, followed by '.' ('\u005Cu002E'), followed by one or more decimal digits representing the fractional part of m
If m is less than 10-3 or greater than or equal to 107, then it is represented in so-called "computerized scientific notation." Let n be the unique integer such that 10n ≤ m < 10n+1; then let a be the mathematically exact quotient of m and 10n so that 1 ≤ a < 10. The magnitude is then represented as the integer part of a, as a single decimal digit, followed by '.' ('\u005Cu002E'), followed by decimal digits representing the fractional part of a, followed by the letter 'E' ('\u005Cu0045'), followed by a representation of n as a decimal integer, as produced by the method Integer.toString(int).
它没有明确说明:分隔符是 .
但 Double
的 toString()
方法的所有用例都明确了 .
字符作为分隔符。
通过推导,我们可以将 .
视为字符分隔符。
关于java - Double.tostring() 使用什么小数点分隔符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45121856/