jQuery.Calculation プラグインを使用して合計で行を計算していますが、合計は小数点以下のすべてを無視しています。修正は正規表現にあると思われますが、どこにあるのかわかりません。
次のメソッドは、ヨーロッパの小数のデフォルトを正しく設定する必要があります。行ごとに機能しますが、計算の合計メソッドは小数を無視しています。以下の正規表現は公式リリースの修正ですが、まだ正しく機能していません。
$.Calculation.setDefaults({
reNumbers: /(-|-\$)?(\d+(.\d{3})*(\,\d{1,})?|\.\d{1,})/g
, cleanseNumber: function (v) {
return v.replace(/[^0-9,\-]/g, "").replace(/,/g, ".");
}
});
例: 7834,45 * 1 はその行の 7834,45 の正しい合計を示しますが、jQuery.Calculation sum メソッドを使用して合計を計算すると、これは小数点なしで 7834 となります。
これは合計を計算するコードで、多かれ少なかれ例からそのまま引き出されています
$("[id^=total_umva_item_]").calc(
// the equation to use for the calculation
"qty * price",
// define the variables used in the equation, these can be a jQuery object
{
qty: $("input[name^=antall_]"),
price: $("input[name^=price_]")
},
// define the formatting callback, the results of the calculation are passed to this function
function (s) {
// return the number as a dollar amount
return "kr " + s.toFixed(2);
},
// define the finish callback, this runs after the calculation has been complete
function ($this) {
// sum the total of the $("[id^=total_item]") selector
var sum = $this.sum(); <- The sum is calculated without decimals
$("#invoice-totals-net").text(
"kr " + sum.toFixed(2)
);
}
);
米国の数値スタイルのデフォルトの正規表現を使用すると、これは正しく機能しますが,
、小数点記号として機能する計算が必要です