H I O X INDIA
FREE Javascript
Google
Web hscripts.com
 HOME  ||  Scripts  ||  Purchase  ||  Tutorials  ||  Images  ||  Tools  ||  Directories 
  :-)  Send Page   :-)   Feedback   :-)   Register   :-)   Links   :-)   Support   :-)   Bookmarks :-)  
 Forums   Hosting   Internet Stats   Easy Calculation   FUN Games 

Java Script Source
List All
Date & Time
Calendar
Stop Watch script
Slide Show
Image Effect
Mouse Effects
Color Picker Tool
Dynamic Color
Random Generator
Select All
Form Validation
Textbox Counter
Dynamic Form select
Bookmark
Window / User Info
Security / Authenticate
Status Bar
Title Bar
Cursor Position
Country List
Calculators
Delete Repeated Values
Alphanumeric
Free Games





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 language=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



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
- This javascript (misspelled as java script)/HTML code 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.


privacy policy     license     sitemap
© 2004-2005 HIOX INDIA - hioxindia.com

Others