How To Round A Number To The Specified Number Of Decimal Places

The code speaks for itself.

myNumber = 22/7;
//To round the myNumber to 2 number of decimal places we use the toFixed() method
rounded = myNumber.toFixed(2);
alert("My number is " + rounded);

Taxonomy upgrade extras: 

Comments

nice, thank you

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.