Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change default culture settings in a .net web application?

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?

like image 975
ericvg Avatar asked Nov 21 '25 01:11

ericvg


2 Answers

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.

like image 152
Fredrik Mörk Avatar answered Nov 23 '25 13:11

Fredrik Mörk


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.

like image 30
cakeforcerberus Avatar answered Nov 23 '25 13:11

cakeforcerberus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!