Script Categories

Calculators >>> Round.

A simple function to round a decimal number to any number of decimal places you want just by passing it different values.

Add the below code to the <body> section of your page:

<script language="javascript" type="text/javascript"">
/* Visit for full source code
and get more free JavaScript, CSS and DHTML scripts! */
<!-- Begin
function round(number,X) {
// rounds number to X decimal places, defaults to 2
X = (!X ? 2 : X);
return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
document.write('<b>' + round(1,2) + '<br>');
document.write( round(1.2,2) + '<br>');
document.write( round(1.23,2) + '<br>');
document.write( round(1.234,2) + '<br>');
document.write( round(1.2345) + '<br></b>');
// End -->

JavaScript Editor Get Advanced
JavaScript and Ajax Editor,
Validator and Debugger!

1st JavaScript Editor.

Code was highlighted by 1st JavaScript Editor (The Best JavaScript Editor!).