Android - Round to 2 decimal places

goodm picture goodm · Feb 20, 2012 · Viewed 206.4k times · Source

Possible Duplicate:
Round a double to 2 significant figures after decimal point

I know that there are plenty of examples on how to round this kind numbers. But could someone show me how to round double, to get value that I can display as a String and ALWAYS have 2 decimal places?

Answer

OleGG picture OleGG · Feb 20, 2012

You can use String.format("%.2f", d), your double will be rounded automatically.