I want to shorten a number to the first significant digit that is not 0. The digits behind should be rounded.
Examples:
0.001 -> 0.001
0.00367 -> 0.004
0.00337 -> 0.003
0.000000564 -> 0.0000006
0.00000432907543029 -> 0.000004
Currently I have the following procedure:
if (value < (decimal) 0.01)
{
value = Math.Round(value, 4);
}
Note:
- numbers will always be positive
- the number of significant digits will always be 1
- values larger 0.01 will always be rounded to two decimal places, hence the if < 0.01
As you can see from the examples above, a rounding to 4 Decimal places might not be enough and the value might vary greatly.