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

Loading

The code speaks for itself.

<script language="text/javascript">
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);
</script>

About the author

Sudheer is an entrepreneur and software developer. Get more from Sudheer on Twitter.


nice, thank you

nice, thank you

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>. The supported tag styles are: <foo>, [foo].

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
C
m
f
T
W
W
Enter the code without spaces and pay attention to upper/lower case.
By submitting this form, you accept the Mollom privacy policy.