3

So I was working on a website and I was using the following Javascript code

UsdAmount.toLocaleString(siteCulture,
      {style: 'currency', currency: 'USD'})
CadAmount.toLocaleString(siteCulture,
      {style: 'currency', currency: 'CAD'})

And it was working fine with expected results

So that

Culture     Currency    Output
en-us       USD         $123.45
en-us       CAD         CA$123.45
en-ca       USD         US$123.45
en-ca       CAD         $123.45

But this function does not work in Safari, therefore I can not use it.

So I figure I will just do it on the server side in C# and pass the string

But that does not seem to work for two reasons

  1. I can't pass two cultures, a system culture and a currency culture
  2. Doesn't seem to work any way since

    4.ToString("C", new CultureInfo("en-us")) ==> "$4.00"
    4.ToString("C", new CultureInfo("en-ca")) ==> "$4.00"  // No CA$
    

So anyother ideas on formatting currency that works across all browsers?

Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
Mike
  • 5,918
  • 9
  • 57
  • 94
  • 1
    Preparing on serverside is always a good idea. May implement your own rules? – Jonas Wilms May 24 '17 at 13:28
  • right now I am looking into regular expression... the issues are I don't know the international rules to follow – Mike May 24 '17 at 13:29
  • In countries with the euro its 123, 45€ . Thats all i can help you (dont know C and Regex ... ) – Jonas Wilms May 24 '17 at 13:31
  • There is a currency symbol and there is an ISO code. Are you looking for something like new RegionInfo("en-ca").ISOCurrencySymbol ? Related: https://stackoverflow.com/questions/850673/proper-currency-format-when-not-displaying-the-native-currency-of-a-culture – Ondrej Svejdar May 24 '17 at 13:56

1 Answers1

0

If you are running on a server that supports WinRT (Windows 8 or later) then you can use the currency formatter which will do what you want.

Eric MSFT
  • 3,246
  • 1
  • 18
  • 28