本文介绍了如何使用jQuery向价格添加尾随零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,我有一个返回产品价格的脚本.但是价格可能包括也可能不包括尾随零,所以有时我可能会有:
So I have a script which returns a price for a product. However the price may or may not include trailing zeros so sometimes I might have:
258.22
有时候我可能会
258.2
在后一种情况下,我需要使用jQuery添加尾随零.我将如何去做?
In the later case I need to add the trailing zero with jQuery. How would I go about doing this?
推荐答案
您可以使用javascript的toFixed
方法(源),则不需要jQuery.示例:
You can use javascript's toFixed
method (source), you don't need jQuery. Example:
var number = 258.2;
var rounded = number.toFixed(2); // rounded = 258.20
电动工具箱"链接已屈服于linkrot并阻止了Wayback Machine,因此该源没有可用的URL.
Electric Toolbox link has succumbed to linkrot and blocks the Wayback Machine so there is no working URL for the source.
这篇关于如何使用jQuery向价格添加尾随零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!