GetNumberFormat

  • Thread starter Thread starter Roy
  • Start date Start date
R

Roy

Is there a .NET equivalent class function for windows api GetNumberFormat?
If I have to import the api function, what is the namespace for NUMBERFMT
structure it takes as parameter?
 
Roy said:
Is there a .NET equivalent class function for windows api GetNumberFormat?

Yes, .NET has its own globalization classes. Take a look a the
NumberFormatInfo class. You obtain it by creating an appropriate CultureInfo
instance.
 
Is there a .NET equivalent class function for windows api GetNumberFormat?
If I have to import the api function, what is the namespace for NUMBERFMT
structure it takes as parameter?

Yes,

Take a look at CultureInfo and other related classes int he
globalization namespace
 
The api actually can convert a number based on culture (as string). I did not
find any classes under Globalization namespace capable of doing that. Any
more ideas for converting the numbers?
Thanks.
 
Roy said:
The api actually can convert a number based on culture (as string). I did not
find any classes under Globalization namespace capable of doing that.

That's because there aren't any. You use Int32.Parse() and Int32.ToString()
for that. Those, in turn, take an IFormatProvider instance, which any
NumberFormatInfo instance is.

You should read up on how globalization in .NET works. Try
http://msdn.microsoft.com/magazine/cc163824 for starters.
 
The api actually can convert a number based on culture (as string). I did
not
find any classes under Globalization namespace capable of doing that. Any
more ideas for converting the numbers?
Thanks.

See CultureInfo::NumberFormat and System.Globalization.NumberFormatInfo

If all you want is to format a number (not retrieving info on separators,
grouping, and such) you can just use value.ToString( "N" ) and Co.
See "Standard Numeric Format Strings" at
http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx
 
Back
Top