[英]javascript currency format with decimal recognition
i stumbled across your this site while looking for a solution for my problem. 我在寻找解决方案时偶然发现了您的网站。 I m new to javascript but already starting to love it.
我是javascript新手,但已经开始喜欢它。 This one problem i can´t solve on my own yet.
这个问题我还不能自己解决。 Here s the deal:
这是交易:
I need the have a script for Acrobat that tells my field that: 我需要Acrobat的脚本来告诉我的领域:
1. It´sa currency field always ending with (blank)€ 1.这是一个货币字段,始终以(空白)€结尾
2. The user needs to be able to enter prices with 2 decimal place (for example 123,23 €) 2.用户需要输入小数点后两位的价格(例如123,23€)
3. If the user enters 123,00 it should automatically turn into 123 €. 3.如果用户输入123,00,它将自动变成123€。
Like I said I ma newbie in this area but eager to learn, so your help is very much appreciated. 就像我说的那样,我是这个领域的新手,但渴望学习,因此非常感谢您的帮助。
A JS solution to this is to use string.toLocaleString
. 对此的JS解决方案是使用
string.toLocaleString
。 (From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString ) (来自https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString )
var number = 123456.789;
// request a currency format
console.log(number.toLocaleString('de-DE', { style: 'currency', currency: 'EUR'}));
// → 123.456,79 €
Instead of "de-DE" you'll probably want to use your own country code. 您可能要使用自己的国家/地区代码,而不是“ de-DE”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.