JAVA How to remove the comma from the output

DenIf :

I am a completely beginner. I have to find the perimeter of a circle. In the description of the task I see that the expected result is shown with decimal point, but when I solve it, I get the result printed with comma, not a dot. What could be the reason and how can I change my output to be with ".", not ",".

nixau :

You probably have a locale issue. Your system locale is printing the decimal numbers using a comma. Try to use java.text.NumberFormat class in JDK. It allows to change a locale of the output in place.

Your code should look something like this

  public static void main(String[] args) {
    NumberFormat nf = NumberFormat.getInstance(new Locale("en", "US"));

    String val = nf.format(1.03);

    System.out.println(val);
  }

For more information on various locale specifics of displaying a decimal I would recommend to look at https://en.wikipedia.org/wiki/Decimal_separator. Also getting familiar w the standard java.util.Locale class is recommended

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=374341&siteId=1