How to reduce a decimal number in java?

1

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

    
asked by anonymous 19.02.2015 / 21:07

1 answer

2

I already found the answer.

Just use DecimalFormat , like this:

double x = 1.3333;
DefimalFormat df = new DecimalFormat("0,##");
df.format(x);
    
19.02.2015 / 21:17