0

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)
                );
            }
        );

米国の数値スタイルのデフォルトの正規表現を使用すると、これは正しく機能しますが,、小数点記号として機能する計算が必要です

4

1 に答える 1

0

私はそれを働かせました。著者に連絡したところ、彼は以下のデフォルトを渡してくれました。また、総計は行の合計を合計して計算されるため、行の合計でも正しい小数点記号を出力するように注意してください。

$.Calculation.setDefaults({
  // a regular expression for detecting European-style formatted numbers

  reNumbers: /(-|-\$)?(\d+(\.\d{3})*(\,\d{1,})?|\,\d{1,})?/g
  // define a procedure to convert the string number into an actual usable number
  , cleanseNumber: function (v){
     // cleanse the number one more time to remove extra data (like commas and dollar signs)
     // use this for European numbers: v.replace(/[^0-9,\-]/g, "").replace(/,/g, ".")

     return v.replace(/[^0-9,\-]/g, "").replace(/,/g, ".");
  }
})
于 2010-06-22T10:47:14.343 に答える