sing
sing

Reputation: 29

rounding off to 2 decimal place in javascript

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();

Upvotes: 2

Views: 66

Answers (2)

Pratik Joshi
Pratik Joshi

Reputation: 11693

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

Upvotes: 0

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67207

Try to use .toFixed() at this context,

$("#pax1").text((value * 13.21).toFixed(2));

Upvotes: 2

Related Questions