2

I'm new to programming. Today, I have a question regarding jQuery. Currently, I am doing a code whereby if i were to type something in a text box, the value will be generated without refreshing somewhere on the same webpage. The code is currently working, however after I add in the round function, the code does not seem to run anymore. Will appreciate if you are keen to help. Thanks!

 $( "#noofpax1" ) .keyup(function() { var value = $( this ).val(); $( "#pax1" ).text( round ((value * 13.21) ,2 )); }) .keyup(); 

2 Answers 2

2

Try to use .toFixed() at this context,

$("#pax1").text((value * 13.21).toFixed(2)); 
Sign up to request clarification or add additional context in comments.

Comments

0

use toFixed(2) inside text()

dont use round().

DEMO

Reason ur code didnt work : Round a number to the nearest integer.It doesnt accept second parameter.

For details about ur question Check here

3 Comments

Thanks for your reply. I tried using toFixed(2) but it does not work. $( "#noofpax1" ) .keyup(function() { var value = $( this ).val(); $( "#pax1" ).text( value * 13.21 ).toFixed(2); }) .keyup(); Am I doing it correctly? @jQueryAngryBird
Check fiddle i posteed
@sing , i had to say inside text(). Did u check jsFiddle?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.