absolute digits with NumberFormatInfo class

  • Thread starter Adam The Generic
  • Start date
A

Adam The Generic

Hi All,

i am using System.Globalization.NumberFormatInfo class

my usage is..
//--------------
NumberFormatInfo nf = new NumberFormatInfo();
nf.NumberGroupSeparator = ".";
nf.NumberDecimalSeparator = ",";
nf.NumberDecimalDigits = 2;
//---------------

it shows the decimal values which has a decimal part correctly like that
1.415,78
7.455,01

but i need to show absolute digits even if it is a whole number and has no
decimal digit..
74 should be 74,00
45.124 should be 45.124,00

how can i get this format ?

Any help would be appreciated.
 
M

Martin Honnen

Adam said:
Hi All,

i am using System.Globalization.NumberFormatInfo class

my usage is..
//--------------
NumberFormatInfo nf = new NumberFormatInfo();
nf.NumberGroupSeparator = ".";
nf.NumberDecimalSeparator = ",";
nf.NumberDecimalDigits = 2;
//---------------

it shows the decimal values which has a decimal part correctly like that
1.415,78
7.455,01

but i need to show absolute digits even if it is a whole number and has no
decimal digit..
74 should be 74,00
45.124 should be 45.124,00

how can i get this format ?

ToString has an overload that takes a format string:

NumberFormatInfo nf = new NumberFormatInfo();
nf.NumberGroupSeparator = ".";
nf.NumberDecimalSeparator = ",";
nf.NumberDecimalDigits = 2;

decimal[] numbers = { 74, 45124 };
foreach (decimal n in numbers)
{
Console.WriteLine(n.ToString("#,##0.00", nf));
}

output is

74,00
45.124,00
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top