GetNumberFormat

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?
 
J

Jeroen Mostert

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.
 
I

Ignacio Machin ( .NET/ C# MVP )

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
 
R

Roy

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.
 
J

Jeroen Mostert

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.
 
M

Mihai N.

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
 

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