Created
November 6, 2013 08:37
-
-
Save astannard/7332814 to your computer and use it in GitHub Desktop.
Stop javascript treating a number as text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This does not work and gives the wrong figure due to concatination | |
var shiftPrem = $('#Contract_Reward_ShiftPremium').val(); | |
var basePay = $('#Contract_Reward_BasePay').val(); | |
var total = basePay + (basePay * (shiftPrem/100)); | |
//This works by forcing javascript to treat the variables as numbers | |
shiftPrem = $('#Contract_Reward_ShiftPremium').val(); | |
basePay = $('#Contract_Reward_BasePay').val(); | |
total = +basePay + +(basePay * (shiftPrem/100)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment