0

I have a dropdown list and it has values which are to 2 decimal places.

<label for="delivery">Delivery:</label> <select id="delivery" name="delivery"> <option value="1.50">Fast</option> <option value="2.50">Medium</option> <option value="3.50">Slow</option> </select> 

How can I call this in Javascript, I know I have to use the toFixed(2) somewhere in the line below, but I'm unsure where to put it.

var delivery = parseInt($('#delivery').val()); 

Also, would I put it in the div in where it is outputted or in the calculation, or both?

Jonah

3 Answers 3

6

Don't use parseInt() (as it kills the decimals). Use parseFloat() then toFixed():

 var delivery = parseFloat($('#delivery').val()).toFixed(2); 

Note: If you are interested in rounds with toFixed(), reference this question.

Sign up to request clarification or add additional context in comments.

Comments

0

How about

var delivery = parseFloat($('#delivery').val()).toFixed(2); 

Comments

0

use

var delivery = parseFloat($('#delivery').val()).toFixed(2); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.