What is the best way to display only two houses in a float in java

0

I'm creating a simple application in android studio, where I make a split and present its result in an EditText, however I'd like to present only two decimal places, what's the best way to do that?

    
asked by anonymous 24.02.2018 / 22:04

1 answer

1

Use this code to format your decimal places in float or double

float x = (float) 12.309989;
    DecimalFormat df = new DecimalFormat("0.00");
    editText.setText(df.format(x));
    
03.03.2018 / 01:53