【问题标题】:trailing zeros calculation in jquery with points valuesjquery中的尾随零计算与点值
【发布时间】:2015-11-11 03:29:35
【问题描述】:

您好,我正在尝试使用标准方式计算值,例如 12,000.001,678,900.000.36 值,但如果逗号或点存在,它不会计算我的值。这是我的代码jsFiddle

例如

我给出的值

付款已发送 1:12,000.00

付款已发送 2:1,678,900.00

付款已发送 3:0.36

现在已发送的总付款转换为 0.00

已发送总付款:0.00

那么如何正确计算这些值。

【问题讨论】:

  • @GuruprasadRao that 不起作用!

标签: jquery trailing


【解决方案1】:
    function paymentSentSum() {
      var totalPaymentSent = 0;
      var that;
      $(".paymentSentSum").each(function() {
         that = parseFloat(this.value.replace(/\,/g,''));
         if(!isNaN(that) && that != 0) {
            totalPaymentSent += that;
         }
      });
      $("#paymentSentTotalPaymentSent").val((totalPaymentSent).formatMoney(2, '.', ','));
    }

    function addTrailingZerosBookings() {
      var that;
      $(".paymentSentSum").each(function() {
        that = parseFloat(this.value.replace(/\,/g,''));
        if(that && !isNaN(that)) {
            //$("#" + $(this).attr('id')).val(trailingZeros(this.value));
            if(isAlphaNumeric(that)) {
                $("#" + $(this).attr('id')).val(that.formatMoney(2, '.', ','));
            } else {
                $("#" + $(this).attr('id')).val(this.value);
            }
         }
      });
    }

这里用这个。我最初使用 parseFloat 来获取金额,然后应用您的支票。休息就好了。

代码笔:http://codepen.io/anon/pen/JdqLgB

【讨论】:

  • 我猜你弄错了。再读一遍。
  • 查看代码笔 http://codepen.io/anon/pen/JdqLgB 它按预期工作
  • 男人!!!我知道它有效,所以请+1。你仍然没有理解我的问题或回答我的问题!大声笑。
  • 只有一个问题,如果我输入值12000,它会像这样将它转换成12,000.00,但是如果我用逗号输入值12,000,它不会添加尾随零。
  • 如果我输入双逗号,它应该转换成带有尾随零的单逗号。
猜你喜欢
  • 1970-01-01
  • 2018-11-06
  • 2017-09-19
  • 2021-10-31
  • 2014-01-11
  • 2020-05-11
  • 1970-01-01
  • 2014-05-01
相关资源
最近更新 更多