D
Dennis Myrén
Hi.
I use a System.Globalization.NumberFormatInfo
(a System.IFormatProvider derival) instance for formatting numbers.
I want to use the NumberDecimalDigits member property to round the numbers
when formatting them as strings. However, this property does not seem to
help me.
For example:
NumberFormatInfo numberFormat = new NumberFormatInfo();
numberFormat.NumberDecimalDigits = 2;
double d = 1.53075794227797E-14;
string s = string.Format(numberFormat, "d = {0}", d);
Console.WriteLine(s);
Shouldn't this example produce a number with two decimals? In this case, it
does not.
It keeps all decimals.
I know i could use a rounding function like Math.Round to manually round the
numbers.
But in some way, it should be possible to use only a NumberFormatInfo
instance to do the job, shouldn't it?
Regards,
Dennis
I use a System.Globalization.NumberFormatInfo
(a System.IFormatProvider derival) instance for formatting numbers.
I want to use the NumberDecimalDigits member property to round the numbers
when formatting them as strings. However, this property does not seem to
help me.
For example:
NumberFormatInfo numberFormat = new NumberFormatInfo();
numberFormat.NumberDecimalDigits = 2;
double d = 1.53075794227797E-14;
string s = string.Format(numberFormat, "d = {0}", d);
Console.WriteLine(s);
Shouldn't this example produce a number with two decimals? In this case, it
does not.
It keeps all decimals.
I know i could use a rounding function like Math.Round to manually round the
numbers.
But in some way, it should be possible to use only a NumberFormatInfo
instance to do the job, shouldn't it?
Regards,
Dennis