Doubt comma, decimal places Java

Asked

Viewed 39 times

-1

inserir a descrição da imagem aqui

I’m having some doubts, could you help me please.

First: When entering the entry amount. Enter the salary of the first employee: 12854,89 I CAN’T PUT A COMMA TO ADD THE NUMERICAL VALUE.

Second: When generating the mean value(double), as I do to have only two decimal places after the virgular/dot.

  • 1

    https://answall.com/q/16276/112052 - click on [Edit] and put the code as text. Putting it as an image is not ideal, understand the reasons reading the FAQ.

  • I appreciate the tip cleared one of my doubts. You could tell me First: When entering the input value. Enter the salary of the first employee: 12854,89 I CANNOT PUT A COMMA TO ADD THE NUMERICAL VALUE. This value I can only add if there is a point(.), if there is a comma(,) error.

  • 1

    To documentation says that parseDouble uses the same rules of valueOf, which in turn only accepts the point. If you want the comma, you have to use NumberFormat. Ex: https://ideone.com/zG4sP8

1 answer

-1

You can do the following by putting %.2f --> that "2" is the number of decimal places you select in the print:

System.out.printf("A = %.2f%n",average);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.