这是我正在使用的当前代码:
f[0].update(parseFloat($('tier').getValue().replace('$','').replace(',',''))*parseFloat(text.replace('$','').replace(',','')));
我遇到的问题是价格显示没有$
且没有适当的货币。
例如,显示为$29.50
的内容显示为29.5
或应显示为$5.00
的内容显示为5
。
答案 0 :(得分:0)
查看accounting.js中的toFixed()
方法。这将解决您的舍入误差和也正确格式化钱
toFixed() - better rounding for floating point numbers
/**
* Implementation of toFixed() that treats floats more like decimals
*
* Fixes binary rounding issues (eg. (0.615).toFixed(2) === "0.61") that present
* problems for accounting- and finance-related software.
*/
var toFixed = lib.toFixed = function(value, precision) {
precision = checkPrecision(precision, lib.settings.number.precision);
var power = Math.pow(10, precision);
// Multiply up by precision, round accurately, then divide and use native toFixed():
return (Math.round(lib.unformat(value) * power) / power).toFixed(precision);
};