简体   繁体   中英

Decimalformat: unwanted replace of dot with comma in JTable

I have a problem displaying the numbers in JTable. If I try to format the number 3.456007 with DecimalFormat using:

DecimalFormat formatter = new DecimalFormat("#.###"); 

The output in JTable is 3,456 instead of 3.456 . If I don't format the number than the result is correct with dot: 3.456007 How can I show only 3 decimal places without losing the dot ?

The important thing to note here is that the "." character in your format does not mean dot. It means: decimal separator corresponding to the Locale .

You can have an actual "." by explicitly setting a Locale where the decimal separator is indeed a dot. Example:

    NumberFormat df = NumberFormat.getInstance(Locale.ENGLISH);
    System.out.println(df.format(12.3456)); //prints 12.346

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM