Categories:

Home / Free JavaScripts / Math Related / Here

Cut & Paste Round number to x decimals

Credit: Jason Moon

Description: A useful utility that rounds any number to the specified decimal place. This is needed because JavaScript doesn't have any built-in methods for the task. The function takes two parameters- a number (has to be a number datatype), and the number of places to round it to.

Example: n/a

Directions: Add this script to your page:

To round numbers using it, simply invoke the function:

roundit(78.4333, 2)

where the first parameter (78.4333) is the number to round, and the second (2), the number of decimals to round it to. For example, the following alerts this processed number:

<script>
//alerts 78.43
alert(roundit(78.4333,2))
</script>


JavaScript Tools:
Site Info

CopyRight 1998-2012 JavaScript Kit. NO PART may be reproduced without author's permission.