[英]How to change the decimal separator of DecimalFormat from comma to dot/point?
[英]how to change the size of a number before the decimal point with DecimalFormat method
如何限制整數本身的位數,而不僅限於小數點后數字的小數部分?
例如,使用數字54321.12574857f和DecimalFormat(“ ## 0。##”)方法; 它應該返回543.12或321.12,小數點后的兩個小數位是正確的,但是我想將小數點前的數字減少到僅3。這是怎么做的?
輸入數字54321.12574857后,我正在使用## 0。##的DecimalFormat方法的參數,但我期望的是543.12或321.12,而不是得到的54321.12
由DecimalFormat方法更改的唯一數字是小數點后的數字
float inputNumber = 54321.12574857f;
DecimalFormat decimalFormat = new DecimalFormat("##0.##");
String newNumber = String.valueOf(decimalFormat.format(inputNumber));
System.out.println(newNumber);
試試這樣的事
DecimalFormat decimalFormat = new DecimalFormat("##0.##");
String newNumber = String.valueOf(decimalFormat.format(inputNumber/100));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.