Keep two decimal places {
Method One: {
Double c=3.154215;
Java.text.DecimalFormat myformat=new Java.text.DecimalFormat ("0.00");
String str = Myformat.format (c);
}
Way two: {
Java.text.DecimalFormat DF =new Java.text.DecimalFormat ("#.00");
Df.format (the number you want to format);
Example: New Java.text.DecimalFormat ("#.00"). Format (3.1415926)
#.00 represents two decimal places #.0000 four decimal places and so on ...
}
Way three: {
Double d = 3.1415926;
string result = string. Format ("%.2f");
%.2f%. Indicates that any number of digits before the decimal point 2 indicates that the result of the two-bit decimal format is F for floating-point
}
}
Rounded
Double F = 111231.5585;
BigDecimal B = new BigDecimal (f);
Keep 2 decimal places
Double f1 = B.setscale (2, bigdecimal.round_half_up). Doublevalue ();
}
JAVA BigDecimal decimal point processing