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();
zerkms
  • 249,484
  • 69
  • 436
  • 539
sing
  • 29
  • 1
  • 4

2 Answers2

2

Try to use .toFixed() at this context,

$("#pax1").text((value * 13.21).toFixed(2));
Rajaprabhu Aravindasamy
  • 66,513
  • 17
  • 101
  • 130
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

Community
  • 1
  • 1
Pratik Joshi
  • 11,485
  • 7
  • 41
  • 73
  • 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 – sing Jul 23 '14 at 11:01
  • Check fiddle i posteed – Pratik Joshi Jul 23 '14 at 11:02
  • @sing , i had to say inside text(). Did u check jsFiddle? – Pratik Joshi Jul 23 '14 at 11:31