To remove useless zeros after the point, I use the following method
if (("" + unitValue).endsWith(".0")) {
return String.format("%.0f %s", unitValue, unitFaName);
} else if (unitValue < 0.001) {
return String.format("%f %s", unitValue, unitFaName);
} else {
return String.format("%s %s", String.valueOf(unitValue), unitFaName);
}
This method has edited the following values :
1.000000 => 1
2 zero after the point and before one
1.001000 => 1.001
But can not modify the following values:
But more than two zero after the point and before one can not be modified
1.0001000
1.0000100
...
That's why I used the following condition to avoid scientific notation top Numbers (1.0001000 , 1.0000100)
if(unitValue<0.001){
return String.format("%f %s", unitValue, unitFaName);
}
In what way do I modify the following numbers?
more than two zero after the point and before one
1.0001000
1.0000100
...
I can not use Decimalformat
or String,Format
because Digits after the point is not fixed numbers