How can i round off this particular code to show only 2 decimal places.
double sum = ((3.141592654/4*(tbmODInput)*(tbmODInput))-(3.141592654/4*(pipeODInput)*(pipeODInput)))*muckUpInput;
volume_per_meter_result.setText(String.valueOf(sum));
CodePudding user response:
Kotlin
val value = 3.14159265358979323
// round to 2 decimal: 3.14
val formated = "Rounded is: %.2f".format(value)
Java
double value = 3.14159265358979323;
// round to 2 decimal: 3.14
String formated = String.format("Rounded is: %.2f", value);
CodePudding user response:
For Java:
double value = 3.141592654;
String formated = String.format("Rounded is: %.2f", value);
For Kotlin:
val value = 3.141592654
val formattedText= "Rounded is: %.2f".format(value)