Rounding Decimals Script
This free javasrcipt is used for rounding decimals. This javascript is for rounding decimal places.
Features
Javascript rounding decimals script rounds the decimal place. Just copy the code into your page and use it.
Preview
Downloads
Javascript Code <!--Script by hscripts.com--> <!-- Free javascripts @ https://www.hscripts.com --> <script type="text/javascript"> function rnd() { var num1=document.getElementById("no1").value; var num2=document.getElementById("no2").value var op=document.getElementById("op").value; var rn=document.getElementById("rd").value; var res; num1=parseFloat(num1); num2=parseFloat(num2); if(isNaN(num1) || isNaN(num2)) { alert("please check the number entered by you"); } else { switch(op) { case "+" : res=num1+num2; break; case "-" : res=num1-num2; break; case "/" : res=num1/num2; break; case "*" : res=num1*num2; break; case "%" : res=num1%num2; break; } } var rs = new Number(res); var lrs=rs.toFixed(rn); document.getElementById("res").value=lrs; } function ncheck(event,no) { var kc; if(window.event) { kc=event.keyCode; } else { kc=event.which; } var num=no.value; if(kc==46) { if(num.indexOf(".")==-1) { return true; } else { return false; } } if(kc==45) { if(num=="") { return true; } else { return false; } } if(kc==48) { if(num.indexOf("-")==0 && num.length==1) { return false; } if(num=="") { return false; } else { return true; } }if (kc!=8 && kc!=0) { if (kc<49||kc>57) { return false; } } } function elzero(num) { var no=num.value; if(parseInt(no.charAt(0))==0) { while(parseInt(no.charAt(0)) == 0) { num.value=no.substring(1); } } } </script> <!-- Script by hscripts.com -->
HTML Code <!--Script by hscripts.com--> <!-- Free javascripts @ https://www.hscripts.com --> <form name="frm1"> <table> <tr><td align="center" style="color: #3D366F; font-size:13px;">FirstNumber</td><td align="center" style="color: #3D366F; font-size:13px;">Operator</td><td align="center" style="color: #3D366F; font-size:13px;">SecondNumber</td></tr> <tr><td align="center" style="color: #3D366F; font-size:13px;text-decoration:none;cursor:pointer;"><input type="text" name="no1" id="no1" size="5" onkeypress="return ncheck(event,no1)" onblur="elzero(no1)"></td> <td align="center"><select name="op" id="op"> <option value="+" default>+</option> <option value="-">-</option> <option value="/">/</option> <option value="*">*</option> <option value="%">%</option> </select></td> <td align="center"><input type="text" name="no2" id="no2" size="5" onkeypress="return ncheck(event,no2)"></td></tr><tr></tr> <tr><td colspan="3" align="center" style="color: #3D366F; font-size:13px;">Round Decimal Upto <select name="rd" id="rd"> <script type="text/javascript"> for(var i=1;i<=10;i++) { document.write("<option value="+i+">"+i+"</option>"); } </script> </select></td> </tr><tr></tr><tr><td colspan="3" align="center"><input type="button" value="Calculate" onclick="rnd()"></td></tr> </table><br> <table> <tr><td colspan="1" align="right" style="color: #3D366F; font-size:13px;">Result <input type="text" name="res" id="res" readonly></td></tr> </table> ©<a href="https://www.hscripts.com">hscripts.com</a></form> <!-- Script by hscripts.com -->
Release Date - 07-04-2008 Get free version without ©copyright link for just $5/ -
For customization of this script or any script development, mail to support@hscripts.com
Usage
Just follow the below instructions to have your own Decimal Rounding Script Copy the HTML code given above,save it with .html extension. Just copy and paste the javascript code given above in <head> section of HTML. Run the file in any web browser,to have your own decimal rounder.
License
The javascript (misspelled as java script) is given under GPL License.
i.e. Free use for those who use it as it is.
Free, if your modification does not remove our copyright information and links.
Detailed License information can be found here .
You can purchase the script if your requirements does not meet GPL License terms.
Related Scripts