简体   繁体   中英

ASP.NET Client-side localization and Javascript

I am building a web-based application which supports French language. When in ASP.NET I set the Thread.CurrentThread.CurrentCulture to fr-FR. Everything work in ASP.NET in French format which is great. However if I have a code such as below, I run into incompatibility issues between ASP.NET and Javascript:

var value = <%:Model.Amount%>;
var total = value * 12;

The above will be rendered as:

var value = 1023,00;
var total = value * 12;

And get the following error message from the browser:

Uncaught SyntaxError: Unexpected number

Is there anyway to tell the browser what locale to work with? I tried the "accept-language" meta tag and that did not help.

NOTE: I am not looking for finding out how I can render the decimal values into the screen without culture, well aware of:

<%:Convert.ToString(Model.Amount, new System.Globalization.CultureInfo(""))%>

I am looking for a way to tell the browser what my locale is, so that I wouldn't have to go through all pages of the project and see where things are breaking and change them.

have you tried accounting.js http://josscrowcroft.github.io/accounting.js/

accounting.js is a tiny JavaScript library for number, money and currency formatting, with optional excel-style column rendering (to line up symbols and decimals). It's lightweight, fully localisable and has zero dependencies.

or

<%:Model.Amount.ToString("N2", CultureInfo.CreateSpecificCulture("en-US").Replace(",", "")%>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM