2016-05-28 107 views
-2

我嘗試數學2浮點數並將它們添加到ajax查詢。但沒有工作。這裏是我的代碼:jQuery數學兩個浮點數

// All padejPremium_X is 225.00 
    var amount = $("#padejPremium_2").val()/100) * 2; // (225.00/100) * 2 = 4.5 
    var data = { 
     DueAmount0: $("#padejPremium_1").val() + 10.00, 
     DueAmount1: $("#padejPremium_2").val() + amount, 
     DueAmount2: $("#padejPremium_3").val() + amount, 
     DueAmount3: $("#padejPremium_4").val() + amount, 

如果有人給出一個想法,我會很高興。提前致謝。

+1

'無功量= parseFloat($( 「#padejPremium_2」)VAL()。)/ 100 * 2; 'https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/parseFloat – Satpal

+1

'val()'返回一個字符串 – charlietfl

回答

1

您剛剛在第一行中錯過了(。檢查下面的代碼:

var amount = ($("#padejPremium_2").val()/100) * 2; // (225.00/100) * 2 = 4.5 
var data = { 
    DueAmount0: $("#padejPremium_1").val() + 10.00, 
    DueAmount1: $("#padejPremium_2").val() + amount, 
    DueAmount2: $("#padejPremium_3").val() + amount 
    } 
    console.log(data); 

檢查這裏的演示:

JSFiddle(檢查控制檯)