看一看toFixed()
方法从accounting.js。这将解决您的舍入误差&也格式化钱正确
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);
};
链接:http://josscrowcroft.github.com/accounting.js/#methods
我倒是建议使用Numeral.js,用于格式化和操作的数字图书馆。还支持货币。 http://numeraljs.com – joko13
这是为magento,虽然... – ryanb4614