JavaScript 中是否有将值转换为特定语言环境格式的功能? [英] Is there a functionality in JavaScript to convert values into specific locale formats?

查看:19
本文介绍了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天全站免登陆