TooCooL
TooCooL

Reputation: 21202

jquery treating numbers as strings

here is the jsfiddle of what I am trying to calculate. I dont dont know how to convert those strings into integers. http://jsfiddle.net/Ygsrv/2/

and here is the code:

$('#get').click(function(){
    var priceProduct = 18.9
    var length = $("#awp_group_5 option:selected").text().replace(/cm$/, '');
    var width = $("#awp_group_4 option:selected").text().replace(/cm$/, '');
    var priceProduct2 = priceProduct + (width + length * 30 );
    alert(priceProduct2);

});

Upvotes: 1

Views: 418

Answers (2)

Prateek Shukla
Prateek Shukla

Reputation: 595

use this to parse the string as Integer-

parseInt(YourStringVar);

Upvotes: 0

Jaya Mayu
Jaya Mayu

Reputation: 17257

You should use parseInt(yourStringHere);

You should do something as below

var priceProduct2 = priceProduct + (parseInt(width) + parseInt(length) * 30 );

Check out this example at fiddle http://jsfiddle.net/mayooresan/Ygsrv/3/

Upvotes: 4

Related Questions