Che*_*eng 8 java format decimal number-formatting decimalformat
我使用以下DecimalFormat模式:
// Use ThreadLocal to ensure thread safety.
private static final ThreadLocal <NumberFormat> numberFormat =
new ThreadLocal <NumberFormat>() {
@Override protected NumberFormat initialValue() {
return new DecimalFormat("#,##0.00");
}
};
Run Code Online (Sandbox Code Playgroud)
这将执行以下转换:
1 -> 1.00
1.1 -> 1.10
1.12 -> 1.12
Run Code Online (Sandbox Code Playgroud)
我现在有一个额外的要求.
1.123 -> 1.123
1.1234 -> 1.123
Run Code Online (Sandbox Code Playgroud)
这意味着什么时候
我可以在DecimalFormat课堂上指定这种行为吗?