10 Oct 2012

Before I start thank you to Mike Geyser for for bringing this up on Twitter.

Recently I wrote about what is the correct way to display currency in South Africa, which was meant as an interest post rather than anything related to Windows 8 or development – but it seems to be serendipitous in it’s timing. The post referred to the currency format and how you should use a comma to separate Rands & Cents. Windows has always (at least as far back as Windows 98) respected this as the correct currency format in South Africa.

Here you can see Windows 7 (left) and Windows 8 (right) have the same settings.

windows7currencywindows8currency

However with Windows 8, Microsoft have decided to be correct everywhere so if you compare the number format settings in Windows 7 (left) it uses a full stop where Windows 8 (right) uses a comma for number formatting.

windows7numberwindows8number

The problem is that the number format setting is used in .NET for parsing which means that all numeric code parsing code will break in Windows 8 if you have the South African formatting set!

var testOne = Decimal.Parse("10.2"); // works in Windows 7 and before - exception in Windows 8
var testTwo = Decimal.Parse("10,2"); // works in Windows 8 but fails in Windows 7 and before

The exception that will be raised is: System.FormatException: Input string was not in a correct format.

To be fair, Microsoft has said you should never write code like that, you should always provide the culture settings when parsing (this code always works):

var rightWay = Decimal.Parse("10.2", CultureInfo.InvariantCulture);

There are also two other ways to handle this:

CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
var anotherWay = Decimal.Parse("10.2");

In summary when going to Windows 8, make sure you properly test your applications and you test them on the culture that the users will use.

Comments

Web application development's picture

Hey Robert
That is such a nice post. The points mentioned are really helpful for mobile application development for Windows 8 platform. Thanks for sharing the information.

Visitor's picture

There are many countries that use the comma radix and there are many that are protective over it (like Germany). South Africa is not one of those places. Probably because of the mixed British and Dutch colonist roots, period and comma radix are used interchangeably. With the rise of the PC, the comma has been falling into obscurity. Several Internet bank sites either do not support it or have not supported it at one time. Most kids have no idea that comma is "correct". My money is on the period separator winning. Pretty much the same way our official YYYY-MM-DD format is now used by no-one except government.

How does this relate to your article? In short, you should always support both. And if for some reason you don't, you may not want to go with correct either

Robert MacLean's picture

You are spot on, most people in SA do not realise the comma is the separator and assume it is the period and supporting both is the best route.
Rudi Coetzee's picture

You will not believe the days of testing that I had to go through to get to this. And all because of a comma vs a full stop. Bad Microsoft! And the sad part is, our application worked with a number with a 3 decimal accuracy (e.g. 0.765). Even as my example, I used a full stop instead of a comma.

But I agree on the notion of supporting both. Small code change, but a step in the right direction.

Rudi Coetzee's picture

And if I may add, we are writing a comma delimited file, hence the use of a full stop. Unfortunately there will be no way that we change the delimiter to something else.

Add new comment