View Full Version : Rounding In Forms
schnitzel_21st
12-24-2003, 01:17 AM
Hi, i was wondering if it is possible to round a number in a form? possible on / off from a form button?
Thanks for the great service, it's way better that using search engines:D
coothead
12-24-2003, 10:20 AM
Hi there schnitzel_21st,
Do you want something like this...<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta content="mshtml 6.00.2800.1264" name="generator" />
<title>interger conversion</title>
<style type="text/css">
/*<![CDATA[*/
body{font-family:arial;font-size:16px;font-weight:bold;}
div#one{position:absolute;top:50px;left:300px;padding:30px;border:double 6px #000000;}
input{text-align:center;color:#000080;width:60px;}
/*]]>*/
</style>
<script type="text/javascript">
//<![CDATA[
function show_round()
{
var decimal=document.getElementById("decimal").value;
var round=Math.round(decimal);
document.getElementById("interger").value=round;
}
//]]>
</script>
</head>
<body>
<div id="one">
<form action="">
<div>
number:<input id="decimal" type="text"/>
</div>
<div>
interger:<input id="interger" type="text"/>
<input id="button" type="button" value="show" onclick="show_round();return false;" />
</div>
</form>
</div>
</body>
</html>
c:cool::cool:thead
schnitzel_21st
12-25-2003, 04:49 AM
hey i was hopin a bit simpler:) the file i want to stick it into, although it is not complete yet, it is
Speed Calculator (http://www.geocities.com/the_21st_schnitzel/speedcalculator.htm)
Could u please edit it or give me instructions how to make a button to round all answers or for the answers to be rounded when i click the calculate button.
Thanks.:)
coothead
12-25-2003, 09:32 AM
Hi there schnitzel_21st,
Shame that you did not supply the code
in your first post :rolleyes:
Just add Math.round to these lines as shown,
and the results will be rounded :cool:
a.L.value = Math.round(BVal*2.54*3.1416);
a.M.value = Math.round(BVal*2.54);
a.N.value = Math.round(BVal*2.54/2);
a.O.value = Math.round((CVal*JVal)*KVal);
a.P.value = Math.round(DVal*JVal*KVal);
a.Q.value = Math.round(EVal*JVal*KVal);
a.R.value = Math.round(FVal*JVal*KVal);
a.S.value = Math.round(GVal*JVal*KVal);
a.T.value = Math.round(HVal*JVal*KVal);
a.U.value = Math.round(CVal*IVal*KVal);
a.V.value = Math.round(DVal*IVal*KVal);
a.W.value = Math.round(EVal*IVal*KVal);
a.X.value = Math.round(FVal*IVal*KVal);
a.Y.value = Math.round(GVal*IVal*KVal);
a.Z.value = Math.round(HVal*IVal*KVal);
a.AA.value = Math.round(BVal*3.1416);
a.AB.value = Math.round(BVal);
a.AC.value = Math.round(AVal/(CVal*JVal*KVal)*(((BVal*3.1416)*2.54)*(60/100/1000)));
a.AD.value = Math.round(AVal/(DVal*JVal*KVal)*(((BVal*3.1416)*2.54)*(60/100/1000)));
a.AE.value = Math.round(AVal/(EVal*JVal*KVal)*(((BVal*3.1416)*2.54)*(60/100/1000)));
a.AF.value = Math.round(AVal/(FVal*JVal*KVal)*(((BVal*3.1416)*2.54)*(60/100/1000)));
a.AG.value = Math.round(AVal/(GVal*JVal*KVal)*(((BVal*3.1416)*2.54)*(60/100/1000)));
a.AH.value = Math.round(AVal/(HVal*JVal*KVal)*(((BVal*3.1416)*2.54)*(60/100/1000)));
a.AI.value = Math.round(AVal/(CVal*IVal*KVal)*(((BVal*3.1416)*2.54)*(60/100/1000)));
a.AJ.value = Math.round(AVal/(DVal*IVal*KVal)*(((BVal*3.1416)*2.54)*(60/100/1000)));
a.AK.value = Math.round(AVal/(EVal*IVal*KVal)*(((BVal*3.1416)*2.54)*(60/100/1000)));
a.AL.value = Math.round(AVal/(FVal*IVal*KVal)*(((BVal*3.1416)*2.54)*(60/100/1000)));
a.AM.value = Math.round(AVal/(GVal*IVal*KVal)*(((BVal*3.1416)*2.54)*(60/100/1000)));
a.AN.value = Math.round(AVal/(HVal*IVal*KVal)*(((BVal*3.1416)*2.54)*(60/100/1000)));
a.AO.value = Math.round(AVal/(CVal*JVal*KVal)*((BVal*3.1416)*(60/100/1000)));
a.AP.value = Math.round(AVal/(DVal*JVal*KVal)*((BVal*3.1416)*(60/100/1000)));
a.AQ.value = Math.round(AVal/(EVal*JVal*KVal)*((BVal*3.1416)*(60/100/1000)));
a.AR.value = Math.round(AVal/(FVal*JVal*KVal)*((BVal*3.1416)*(60/100/1000)));
a.AS.value = Math.round(AVal/(GVal*JVal*KVal)*((BVal*3.1416)*(60/100/1000)));
a.AT.value = Math.round(AVal/(HVal*JVal*KVal)*((BVal*3.1416)*(60/100/1000)));
a.AU.value = Math.round(BVal);
a.AV.value = Math.round(BVal);
a.AW.value = Math.round(BVal);
a.AX.value = Math.round(BVal);
a.AY.value = Math.round(BVal);
a.AZ.value = Math.round(BVal);
a.BA.value = Math.round(AVal/(CVal*JVal*KVal));
a.BB.value = Math.round(AVal/(DVal*JVal*KVal));
a.BC.value = Math.round(AVal/(EVal*JVal*KVal));
a.BD.value = Math.round(AVal/(FVal*JVal*KVal));
a.BE.value = Math.round(AVal/(GVal*JVal*KVal));
a.BF.value = Math.round(AVal/(HVal*JVal*KVal));
a.BG.value = Math.round(AVal/(CVal*IVal*KVal));
a.BH.value = Math.round(AVal/(DVal*IVal*KVal));
a.BI.value = Math.round(AVal/(EVal*IVal*KVal));
a.BJ.value = Math.round(AVal/(FVal*IVal*KVal));
a.BK.value = Math.round(AVal/(GVal*IVal*KVal));
a.BL.value = Math.round(AVal/(HVal*IVal*KVal));
a.BM.value = Math.round(BVal/2);">
c:cool::cool:thead
schnitzel_21st
12-25-2003, 05:26 PM
hey i was wondering if it would be possible to have the number rounded to two decimal places, and have a on / off button for the rounding? or be possible to have a drop down box for the user t select the rounding?.
Thanks.
illogique
12-25-2003, 05:45 PM
the way i do rounding with 2 decimal is
math.round(xxx*100)/100
coothead
12-25-2003, 06:50 PM
Hi there schnitzel_21st,
assuming that you are not going to
move the goal posts again this is the
final solution. I have placed the '2 d.p.'
button to the right of the reset button.
To save space I have attached the amended code.
c:D:Dthead
coothead
12-25-2003, 07:29 PM
Hi there illogique,
I use... n.toFixed(x);
where n= the decimal N°.
and x= the decimal places.
Thus...
<script type="text/javascript">
<!--
var decimal=6.4078534.toFixed(3);
alert(decimal);
//-->
</script>
c:cool::cool:thead
schnitzel_21st
12-25-2003, 09:42 PM
Thanks, sorry bout changing what i wanted so much lol:)
again, thanks:)
vBulletin® v3.6.7, Copyright ©2000-2010, Jelsoft Enterprises Ltd.