【发布时间】:2022-01-11 23:48:51
【问题描述】:
import java.text.DecimalFormat;
public class FormatTest {
public static void main(String[] args) {
DecimalFormat df = new DecimalFormat("0.0");
System.out.println(df.format(10.4)); // prints 10,4 instead of 10.4
System.out.println(df.format(100.5)); // prints 100,5 instead of 100.5
System.out.println(df.format(3000.3));// prints 3000,3 instead of 3000.3
}
}
我上面的代码的输出如下,用逗号作为小数分隔符,而通常它应该是一个点。我使用带有 Maven 的 NetBeans 12.5。
Java 似乎使用我的本地小数分隔符而不是点。另外,我需要强制点 (".") 作为唯一的分隔符。
--- exec-maven-plugin:3.0.0:exec (default-cli) @ FormatTest ---
10,4
100,5
3000,3
【问题讨论】:
标签: java decimalformat