简体   繁体   English

jQuery:如何限制字符数?

[英]jQuery: How do I restrict number of chars?

I am writing an application which generates a price for something. 我正在编写一个会为某些价格生成价格的应用程序。 Lets say we get an output like this: 假设我们得到这样的输出:

24543.66666667 € 24543.66666667€

What does the jQuery function need to look like for achieving the following format: 为了实现以下格式,jQuery函数需要什么样的外观:

24.543,66 € 24.543,66€

?

(please note that the dot in the first price needs to be replaced by a comma) (请注意,第一个价格中的点需要用逗号替换)

Check out the Number format 查看数字格式

The formatting and rounding you asked can be done like this: 您要求的格式和舍入可以这样完成:

var nb = new Number(24543.6666667);
var result = Number(nb.toFixed(2)).toLocaleString("nl-NL");

check: http://jsfiddle.net/5A6q3/1/ 检查: http : //jsfiddle.net/5A6q3/1/

note that i've used the Dutch locale because this locale is using the , and . 注意,因为该区域设置使用,我用荷兰语的区域设置,. signs as you wanted. 想要的迹象。 This can be used with any locale you want though. 但是,它可以与您想要的任何语言环境一起使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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