JavaScript中是否有将函数转换为特定区域设置格式的功能? [英] Is there a functionality in JavaScript to convert values into specific locale formats?

查看:167
本文介绍了JavaScript中是否有将函数转换为特定区域设置格式的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有内置的JavaScript函数将字符串转换为特定的语言环境(在我的情况下是欧元)?

Is there a built in function of JavaScript to convert a string into a particular locale (Euro in my case)?

例如。 50.00 应转换为 50,00€

推荐答案

50.00 是无单位值。你能做的最好的事情是将 50.00 转换为 50,00 ,然后追加你自己。因此,只需使用 Number.toLocaleString()

50.00 is a unit-less value. The best you can do is convert 50.00 to 50,00 and then append the yourself. Therefore, just use Number.toLocaleString().

var i = 50.00;
alert(i.toLocaleString() + ' €'); // alerts '50.00 €' or '50,00 €'

演示→

  • How can I format numbers as money in JavaScript? (the big one; ~70k views)
  • Convert to currency format
  • Format currency using javascript
  • how do i print currency format in javascript
  • JavaScript: Format number/currency w/regards to culture like .NET's String.Format()? (possibly useful, if you're using ASP.NET)
  • format number to price

这篇关于JavaScript中是否有将函数转换为特定区域设置格式的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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