Totzkeeeeee's Blog

Just because I can...

  Home  |   Contact  |   Syndication    |   Login
  189 Posts | 4 Stories | 186 Comments | 341 Trackbacks

News


My blog is worth $14,678.04.
How much is your blog worth?

Article Categories

Archives

Post Categories

Image Galleries

Blog Roll

Cool Sites

You want to display a value as currency using the format of the culture of the local machine.  The documentation is not too clear on how you use this stuff so I have a little sample that I managed to get working.  Here you go:

In C#:

using System;
using System.Globalization;

namespace ConsoleApplication1
{

    class Class1
   
{
       
[STAThread]
       
static void Main(string[] args)
       
{
            NumberFormatInfo numberInfo = CultureInfo.CurrentCulture.NumberFormat;
            double myAmount = 10.815;
            Console.WriteLine(Math.Round(myAmount, 2).ToString("c", numberInfo));
            Console.ReadLine();

        }
    }
}

In VB:

Imports System.Globalization

 

 

Module Module1

 

    Sub Main()

 

        Dim numberInfo As NumberFormatInfo = CultureInfo.CurrentCulture.NumberFormat

        Dim myAmount As Double = 10.815

 

        Console.WriteLine(Math.Round(10.815, 2).ToString("c", numberInfo))

        Console.ReadLine()

 

 

    End Sub

 

End Module

posted on Monday, February 28, 2005 7:10 PM

Feedback

# re: HOWTO: IFormatProvider, Culture and ToString() 9/12/2005 2:02 PM Curt Teunissen
Thanks, simple example but makes the documentation make sense now.

# re: HOWTO: IFormatProvider, Culture and ToString() 9/6/2007 5:02 AM Kerem Ispirli
this post gave great help to understand what was and how to use damn iFormatProvider. it's important especially when working with ms office files (e.g. excel) on a windows with culture info other than en-us. Thanks!

Post Feedback

Title:
Name:
Email: (never displayed)
Url:
Comments: 
Please add 1 and 8 and type the answer here: