custom string currency

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

does anyone know how to produce the following
custom string for formatting currency inc the appropriate
currency symbol for the country

i could use String.Format("{0:C}", 2000)
which will return £2000.00
but i do not want to show the decimal place i.e
£2000
thanks
 
Richard Steele (Basemap)
does anyone know how to produce the following
custom string for formatting currency inc the appropriate
currency symbol for the country

i could use String.Format("{0:C}", 2000)
which will return ?2000.00
but i do not want to show the decimal place i.e
?2000

Have you tried creating a new NumberFormatInfo and setting
CurrencyDecimalDigits to 0 and setting the CurrencySymbol property
appropriately?

For example:

using System;
using System.Globalization;

public class Test
{
static void Main()
{
NumberFormatInfo nfi = (NumberFormatInfo)
NumberFormatInfo.CurrentInfo.Clone();

nfi.CurrencySymbol = "#";
nfi.CurrencyDecimalDigits = 0;

Console.WriteLine (string.Format (nfi, "{0:C}", 15.25));
}
}

produces:

#15
 
Jon
is there a way that the currency symbol using numberformatinfo can be
extracted from windows settings otherwise i would of used
String.Format("{0:£#,##0;(£#,##0);0}", 2000.00);
 
Richard Steele (Basemap)
is there a way that the currency symbol using numberformatinfo can be
extracted from windows settings otherwise i would of used
String.Format("{0:?#,##0;(?#,##0);0}", 2000.00);

Well, the code I gave before takes the current NumberFormatInfo and
clones it before changing the settings on the cloned value.
 
Technically in Jons code, you could omit the line where he reset the
CurrencySymbol, and it should work fine. Just change the DecimalDigits
to 0 and you should be all set.
 
thanx works like a dream
--
Thanks
Richard


Jon Skeet said:
Richard Steele (Basemap)


Well, the code I gave before takes the current NumberFormatInfo and
clones it before changing the settings on the cloned value.
 
--
Thanks
Richard


Jon Skeet said:
Richard Steele (Basemap)


Well, the code I gave before takes the current NumberFormatInfo and
clones it before changing the settings on the cloned value.
 

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

Back
Top