Using NumberStyles to parse numbers in C# .NET Part 3

Exercises in .NET with Andras Nemes

In the previous post we looked at some more values in the NumberStyles enumeration. In this finishing post we’ll look at some more compact enumeration values and how you can pass in your own number format provider for customised and culture-independent solutions.

We’ve seen that you can combine the NumberStyles enumeration values like here:

It can be cumbersome to keep adding these flags to make sure all currency formats are covered. NumberStyles includes some composite values including NumberStyles.Currency. The Currency value combines all styles except for AllowExponent. If you start typing “NumberStyles.” in Visual Studio and investigate any of the values whose name does NOT start with “allow” then IntelliSense will show you the list of flags included in the composite. So the above currency example can be simplified as follows:

We cannot only parse “normal” numbers, i.e. numbers of the decimal system but hexadecimal numbers as well. Consider the…

View original post 197 more words

Advertisements
This entry was posted in Brian By Experience. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s