0

I am trying to modify this slider to create a new total. I have already added an additional field called fees that takes the (amount * (duration * 1.15)). Now I am just stuck in trying to combine the amount + fees to generate a new total. When I do it now, it just concatenates the amount and fees.

var $amount = slider == 1?val:$("#amount").val();
var $duration = slider == 2?val:$("#duration").val();

$fees = "$" + ($amount * $duration)*.15;
$total = "$" + ($amount + ($amount * $duration)*.15);

I know it has something to do with converting the string to value because when I multiply $amount * $fees it does work, but I have been reading SO and jQuery API for the last hour without any progress.

Any help is appreciated! Thanks!

1 Answer 1

1

Use parseInt() as shown :

var $amount = parseInt(slider) == 1?parseInt(val):parseInt($("#amount").val());

or parseFloat() as shown :

var $amount = parseFloat(slider) == 1?parseFloat(val):parseFloat($("#amount").val());
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! Worked perfectly. Would never have figured that out myself!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.