JavaScript Scripts





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
Free Java Script Codes
Javascript List All
Slide Show Slide Show
Ad Display Ad Display
Image Effect Image Effect
Animated Image Effects Animated Image Effects
Form Validation Form Validation
Color Picker Tool Color Picker Tool
Formatting Forms Formatting Forms
Select All Select All
Dynamic Form Select Dynamic Form select
Dynamic Color Dynamic Color
Calendar Script Calendar
Textbox Counter Textbox Counter
Alphanumeric Alphanumeric
Date Time Script Date & Time
Stop Watch Script Stop Watch script
Delete Repeated Values Delete Repeated Values
Pagination Pagination
Random Generator Random Generator
Animated Text Animated Text
Cursor Position Cursor Position
User Info Window / User Info
Security Security / Authenticate
Bookmark Bookmark
Mouse Effects Mouse Effects
Title Bar Title Bar
Status Bar Status Bar
Country List Country List
Free Games Free Games
Calculators Calculators
 




Rounding Decimals Script


About
This free javasrcipt is used for rounding decimals. This javascript is for rounding decimal places.


Features
a) Javascript rounding decimals script rounds the decimal place.
b) Just copy the code into your page and use it.

Preview

Rounding Decimals
FirstNumberOperatorSecondNumber
Round Decimal Upto 

Result 
©hscripts.com


Code
  Javascript Code
<!--        Script by hscripts.com          -->
<!--        copyright of HIOX INDIA         -->
<!-- Free javascripts @ http://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          -->
<!--        copyright of HIOX INDIA         -->
<!-- Free javascripts @ http://www.hscripts.com -->
<!-- Script by 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>
&copy;<a href="http://hscripts.com">hscripts.com</a>
</form>

Release Date - 07-04-2008
Get free version without ©copyright link for just 5 price

For customization of this script or any script development, contact us at support@hscripts.com


Usage
Just follow the below instructions to have your own Decimal Rounding Script
a) Copy the HTML code given above,save it with .html extension.
b) Just copy and paste the javascript code given above in <head> section of HTML.
c) 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 the codes as it is.
- Free, if your modification does not remove our copyright information and links.
- Click Here for detailed license information.
- You can purchase the script if your requirements does not meet our GPL License terms.
Other Links

web hosting