Is it possible to apply multiple formatting simultaneously to a double?
For example, I want something like this
double d = 1234.567;
string format = ?
// sig digit 4 , digit after decimal 4 , format = combination of G4 and F4 , G4F4?
d.toString(format) => "1235.0000"
Here, "G4" limits the significant digits to 4 and "F4" determines the number of digits after decimal point.
I know it is possible by using 2 separate format
Double.Parse((1234.567).ToString("G4")).ToString("F4") => "1235.0000"
Some more example
//sig digit 3 , digit after decimal 0 , format = combination of G3 and F0
d.toString(format) => "1230"
//sig digit 8 , digit after decimal 8 , format = combination of G8 and F8
d.toString(format) => "1234.56700000"
//sig digit 1 , digit after decimal 1 , format = combination of G1 and F1
d.toString(format) => "1000.0"
var str = (1234.567m).ToString("0000.0000")
? It returns"1234.5670"
and returns"0034.5670" for 34.567
1234.567
to output as1000.0
you should round it then use a format string. To output it as1234.56700000
you just need a format string.