JQuery 数字格式
关于这个基本功能有太多的问题和答案,我只见树木不见森林。
在 Java 中只有一个简单的答案(java.text.NumberFormat
及其子类),因此我确信大多数插件、问题和答案最终都会成熟为 JQuery 的事实上的标准。
这个插件是迄今为止我发现的最好的插件,但我不知道它是否仍在开发,是否成熟等。
http://plugins.jquery.com/project/numberformatter
有更好的解决方案吗?是否成熟/活跃,足以依赖?
编辑:
我希望能够根据Java使用的相同格式模式来格式化货币、小数、整数,以便可以格式化客户端接收的数据,而无需先将其发送到服务器。
例如,
将 1000
格式化为 $1,000
或 1,000.00
等(区域设置支持很好)
似乎 http://plugins.jquery.com/project/numberformatter 可以完成这项工作,但问题是:“我使用的东西正确吗?”或“有更好的方法吗?”
There are way too many questions and answers about this basic functionality, I cannot see the wood for the trees.
In Java there is only one simple answer (java.text.NumberFormat
and its subclasses) so I'm sure the majority of plugins, questions and answers will mature eventually to a de-facto standard for JQuery.
This plugin is the best I found so far, but I don't know if it's still developed, is mature etc.
http://plugins.jquery.com/project/numberformatter
Is there a better solution? Is it mature / active enough to rely on?
Edit:
I would like to be able to format currencies, decimal, integers based on the same format patterns Java uses, so that data recieved on the client side can be formatted without sending it first to the server.
e.g.
Format 1000
to $1,000
or 1,000.00
etc (locale support is nice)
Seems that http://plugins.jquery.com/project/numberformatter does the job but the question was: "Am I using the right thing?" or "Is there a better way to do so?"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我建议您查看这篇文章,了解如何使用 javascript 处理基本格式:
来源:http: //www.mredkj.com/javascript/numberFormat.html
虽然 jQuery 可以通过一百万种不同的方式让你的生活变得更轻松,但我想说这有点矫枉过正了。请记住,jQuery 可能相当大,当您在页面上使用它时,用户的浏览器需要下载它。
当使用 jQuery 时,您应该退后一步,问问它是否有足够的贡献来证明下载库的额外开销是合理的。
如果您需要某种高级格式(例如您链接的插件中的本地化内容),或者您已经包含了 jQuery,那么可能值得考虑一下 jQuery 插件。
旁注 - 如果您想了解一下过度使用的情况,请查看此内容 jQuery。
I would recommend looking at this article on how to use javascript to handle basic formatting:
source: http://www.mredkj.com/javascript/numberFormat.html
While jQuery can make your life easier in a million different ways I would say it's overkill for this. Keep in mind that jQuery can be fairly large and your user's browser needs to download it when you use it on a page.
When ever using jQuery you should step back and ask if it contributes enough to justify the extra overhead of downloading the library.
If you need some sort of advanced formatting (like the localization stuff in the plugin you linked), or you are already including jQuery it might be worth looking at a jQuery plugin.
Side note - check this out if you want to get a chuckle about the over use of jQuery.
使用 jQuery Number Format 插件,您可以获得格式化的数字三种方法之一:
如果您不喜欢这种格式,或者需要本地化,还有其他参数可以让您选择数字的格式:
.number( theNumber,decimalPlaces,decimalSeparator,thousandSeparator )
您还可以获取来自 GitHub 的 jQuery 数字格式。
Using the jQuery Number Format plugin, you can get a formatted number in one of three ways:
If you don't like the format, or you need to localise, there are other parameters that let you choose how the number gets formatted:
.number( theNumber, decimalPlaces, decimalSeparator, thousandsSeparator )
You can also get jQuery Number Format from GitHub.
浏览器开发进度:
https://developer.mozilla .org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString
Browser development progresses:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString
我在 number_format 的基础上编写了 PHP 函数 number_format 的 JavaScript 模拟strong>Abe Miessler addCommas 函数。可能有用。
例如:
I wrote a JavaScript analogue of a PHP function number_format on a base of Abe Miessler addCommas function. Could be usefull.
For example:
如果您需要处理多种货币、各种数字格式等,我可以推荐 autoNumeric。工作是一种享受。现已成功使用它好几年了。
If you need to handle multiple currencies, various number formats etc. I can recommend autoNumeric. Works a treat. Have been using it successfully for several years now.
将此 http://www.mredkj.com/javascript/numberFormat.html 和 < code>$('.number').formatNumber(); 概念结合在一起,您可以使用以下代码行;
例如
1172907.50
的格式将类似于1,172,907.50
Putting this http://www.mredkj.com/javascript/numberFormat.html and
$('.number').formatNumber();
concept together, you may use the following line of code;e.g.
<td class="number">1172907.50</td>
will be formatted like<td class="number">1,172,907.50</td>
http://jquerypriceformat.com/#examples
https://github.com/flaviosilveira/Jquery-Price-Format
html 输入运行实时机会。
//5000.00
//5.000,00
//5,000.00
http://jquerypriceformat.com/#examples
https://github.com/flaviosilveira/Jquery-Price-Format
html input runing for live chance.
//5000.00
//5.000,00
//5,000.00
http://locutus.io/php/strings/number_format/
http://locutus.io/php/strings/number_format/