java - Double.tostring() 使用什么小数点分隔符?

标签 java android

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).

它没有明确说明:分隔符是 .DoubletoString() 方法的所有用例都明确了 . 字符作为分隔符。
通过推导,我们可以将 . 视为字符分隔符。

关于java - Double.tostring() 使用什么小数点分隔符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45121856/

相关文章:

java - Hadoop 序列文件 : process key/value only up to a certain size?

java - 单击按钮时语音识别 Intent 未打开

java - 以编程方式设置 Android 样式

java - 可以使用正则表达式来获取子字符串吗?

android - 通知用户付费版本的应用程序可用

java - StringBuilder - setLength(0) 与 new 实例化,哪个更好?

android - float 操作按钮扩展

java - 在 Android 5 最近屏幕中更改 Activity 的标题/标签

java - 截断和填充整数

java - webview中的JSP/servlet处理