There is no formatting for this.
You can get the fraction of a part of the number and calculate how many zeros are there until you get two digits, and combine the format with it. Example:
double number = 1.0000533535;
double i = Math.Floor(number);
double f = number % 1.0;
int cnt = -2;
while (f < 10) {
f *= 10;
cnt++;
}
Console.WriteLine("{0}.{1}{2:00}", i, new String('0', cnt), f);
Conclusion:
1.000053
Note. This code only works if there is actually a fractional part of the number, and not for negative numbers. You need to add checks for this if you need to support these cases.
Guffa source
share