0

I want only 2 decimals in my code. How can i do that?

Here is my coding:

double conta1 = ((num1*35)/100)*1.05; bomba1.setText(Double.toString(conta1));

Num1=55

Well i only want to result to be 20.21 instead of 20.212500000...

How can I do that?

Tiago
  • 31
  • 4
  • possible duplicate of [How to round a number to n decimal places in Java](http://stackoverflow.com/questions/153724/how-to-round-a-number-to-n-decimal-places-in-java) – ehp May 30 '15 at 19:36

1 Answers1

3

Try this code:

bomba1.setText(new DecimalFormat("#.##").format(conta1));
Chaoz
  • 2,119
  • 1
  • 20
  • 39