Skip to content

Instantly share code, notes, and snippets.

@astannard
Created November 6, 2013 08:37
Show Gist options
  • Save astannard/7332814 to your computer and use it in GitHub Desktop.
Save astannard/7332814 to your computer and use it in GitHub Desktop.
Stop javascript treating a number as text
// 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