It is required to use decimal places in the unit of amount, weight, length, etc. If you only need to retain two places
// By default, two digits are retained (No rounding is performed)
Double sumpric = 0.335333;
String str1 = string. Format ("{0: f}", sumpric );
// Follow the rounding international standards
Double sumpric = 0.335333;
Math. Round (0.333333, 2 );
There is also one (this is acceptable, but sumpric is often a variable in our use process. When it is 0, it will make an error)
Double sumpric = 0.335333;
String A = sumpric. tostring (".##");
______________________________________________________________________________
For more information, see
1. Only n digits are required to be retained.
Float F = 0.55555f;
Int I = (INT) (F * 100 );
F = (float) (I * 1.0)/100;
2. Keep N bits, rounded down.
Decimal d = decimal. Round (decimal. parse ("0.55555"), 2 );
3. Keep n digits rounded
Math. Round (0.55555, 2)
4. Keep n digits rounded
Double dbdata = 0.55555;
String str1 = dbdata. tostring ("F2"); // FN retains N bits, rounded
5. Keep n digits rounded
String result = string. Format ("{0: N2}", 0.55555); // two digits
String result = string. Format ("{0: N3}", 0.55555); // three digits
6. Keep n digits rounded
Double S = 0.55555;
Result = S. tostring ("#0.00"); // a few digits are retained after a few zeros.