Начало
Калькуляторы
Round
Простая функция к раунду десятичное число к любому числу десятичных разрядов.
JavaScript Calculators: Round
<!-- TWO STEPS TO INSTALL ROUND: 1. Copy the coding into the HEAD of your HTML document 2. Add the last code into the BODY of your HTML document --> <!-- STEP ONE: Paste this code into the HEAD of your HTML document --> <SCRIPT LANGUAGE="JavaScript"> <! > <! > <!-- 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); } // End --> </SCRIPT> <!-- STEP TWO: Copy this code into the BODY of your HTML document --> <script> document.write( 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>'); </script>