且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用带有欧洲格式数字的jQuery计算时出现问题

更新时间:2023-09-11 22:40:58

我知道了.我联系了作者,他将下面的默认值传递给了我.您还需要注意的是,总计是通过对行总计求和而得出的,因此请小心在行总计中打印出正确的小数点符号.

I got it working. I contacted the author and he passed me the defaults below. What you need to be aware of too is that the grand total is calculated by summing the row totals so be careful to print out the correct decimal symbol in the row totals as well.

$.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, ".");
  }
})