Format a number based on a required number of decimal places *and* sig figs
Our scientific application allows the user to configure the number of
significant figures and decimal places to use when displaying numeric
values. The formatting is currently being done with this code:-
var sigFigFormatted = valueToConvert.ToString("G" + numberOfSigFigs);
var theFullyFormattedValue = Convert.ToDouble(sigFigFormatted)
.ToString("F" + numberOfDecimalPlaces);
I don't like all this conversion to/from strings, and can't help thinking
there must be a more efficient solution?
No comments:
Post a Comment