JavaScript:格式编号/货币w /关于文化,如.NET的String.Format()? [英] JavaScript: Format number/currency w/regards to culture like .NET's String.Format()?

查看:90
本文介绍了JavaScript:格式编号/货币w /关于文化,如.NET的String.Format()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是有人在2009年已经解决的一个问题,但是我找不到一个像这样的数字的像样的JavaScript库:

This seems like a problem someone would've already solved in the year 2009, but I can't find a decent JavaScript library that will take a number like:

12345.58

并根据特定文化(即nl-nl)或ISO货币代码正确格式化。

And format it correctly based on a specific culture (ie, "nl-nl") or ISO currency code.

dojo显示了承诺,但默认情况下它不包含很多文化,实际上在我的测试中没有正常工作。

dojo showed promise, but it doesn't include many cultures by default, and actually wasn't working properly in my tests.

我基本上想要一些东西当我运行时,这与我为.NET做的100%或接近100%相当:

I basically want something that is 100% or near-100% equivalent to what .NET does for me, when I run:

String.Format([cultureInfo Object],{0: N},myValue代表数字

String.Format([cultureInfo Object], "{0:N}", myValue) ' for numbers

String.Format([cultureInfo Object], {0:C},myValue用于货币

String.Format([cultureInfo Object], "{0:C}", myValue) ' for currency

推荐答案

ASP.NET Ajax框架允许您执行此操作。

The ASP.NET Ajax framework lets you do this.

设置 EnableScriptGlobalization 属性为true。然后,您可以使用 Number.localeFormat 功能格式化数字。

Set the EnableScriptGlobalization property on the ScriptManager to true. You can then use the Number.localeFormat function to format numbers.

这篇关于JavaScript:格式编号/货币w /关于文化,如.NET的String.Format()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆