views:

545

answers:

3

Our web application (.net/C#) formats currency amounts using amount.ToString("c"), shown localized to a few different regions.

Our French Candian users prefer all amounts to be the US format (123,456.99 vs. the default windows way for fr-CA of 123 456,99).

What is the best way to handle that ? Can I simply modify the regional settings on each webserver in windows for fr-ca? or do I need to create a custom culture?

+1  A: 

You can modify the current culture like so:

Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-CA")

You could pull the value from web.config, sure.

EDIT:

Ok, sorry I misunderstood.

This might work:

  decimal d = 1232343456.99M;
  CultureInfo USFormat = new CultureInfo("en-US");      
  Console.Out.WriteLine(d.ToString(USFormat));

This should allow you to just use the USFormat when you're outputting numeric vals.

cakeforcerberus
right, we are doing that currently, but our fr-CA users don't want the standard formatting for that culture, they want US formatting for only dollar amounts. So, its like a hybrid culture.
ericvg
and I'd prefer not to have to hack the code to show the US format for only dollar amounts if the current culture is fr-CA.
ericvg
@pinkmuppet: you can assign "fr-CA" to CurrentUICulture and "en-US" to CurrentCulture; that will make the app load fr-CA resources (string resources and such) while using en-US for formatting numbers and dates.
Fredrik Mörk
@fredrik: yeah, but unfortunatly that would change the date format as well. They *only* want the currency amounts changed. :-)
ericvg
A: 

I would create a User Settings for the application, that would hold the CultureInfo for each user, and create a form to allow each user to edit the property ....

CheGueVerra
+1  A: 

You may want to look into creating a custom culture, providing the mix of formatting rules that you requre. There is an article at MSDN describing how to do it.

In short, you create a CultureAndRegionInfoBuilder object, define the name, set properties, and register it. Check the article for details.

Fredrik Mörk
this is much easier than I thought it would be -- you can load an existing culture, modify one value, and save it as a new culture. perfect.
ericvg