So I am writing a javascript application, and basically if one number is greater than another I want to swap their values:
if(price1 > price2)
{
var temp = price1;
price1 = price2;
price2 = temp;
}
This works fine up until a certain point, but once the numbers starting getting larger, i.e.:
price1: 12345678
price2: 234556
Then the expression will evaluate to false and will do nothing. Does anyone know what the issue is? Thanks!
Are you sure these are being compared as numbers? For example, if you change the code to
does it work? If so
price1andprice2are strings and the prefix+converts them to numbers.