I want to get number, which .ToString() conversion total lenght <= 7. For example
1. 1.23456789 - > 1.23457
2. 12345.789 - > 12345.8
3. 123456789.1234 - > 1.235E8
4. 0.00001234 - > 1.23E-8
I want to use realy fast solution, because work with big file.
This code can solve part of this problem, but it dont work
int power = (int)Math.Log10(f) + 1;
f = f / (float)Math.Pow(10, power);
f = (float)Math.Round(f, 5);
f = f * (float)Math.Pow(10, power);
For example
f = 7.174593E+10
after rounding it become 0.71746
(fine for me)
and when i multiplie it by 10^11
it become 7.17459948E+10
but i expected 7.71746E+10
UPD. As result i want to get string, not a number.
If all you are going to use it for is to display it as string (as said in the update) then use
String.format()
.Example