How to reduce a decimal number in java?

Asked

Viewed 465 times

1

For example, for example... Calculating 8/6 I will have a periodic tithe equal to 1.333333... But I just want to show the user only 2 digits after the comma, that is, 1.33. How can I do this?

  • 1

    http://answall.com/q/40045/101 and http://answall.com/q/16276/101 solve the problem?

1 answer

3

I’ve already found the answer.

Just use the DecimalFormat, thus:

double x = 1.3333;
DefimalFormat df = new DecimalFormat("0,##");
df.format(x);
  • Accept in your own answer then to indicate that the question has been solved.

  • Take your own answer after two days, @Everton.

Browser other questions tagged

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