Eski
07-31-2002, 10:20 AM
I am very new to JavaScript and have been looking how to round a number to two decimal places.
From looking at the tutorial at http://www.javascriptkit.com/javatutors/round.shtml
I added "var result=Math.round(tempnum*100)/100000}"
to the final line of my page, but it does not work!!
<SCRIPT LANGUAGE="JavaScript">
<!--
function calc(f)
{
vx = parseInt(f.x.value);
da = new Date(f.a.value);
db = new Date(f.b.value);
dd = (db.valueOf()-da.valueOf())/1000/60/60/24;
vc = parseInt(f.c.value);
vd = parseInt(f.d.value);
f.answer.value=(vx/365)*dd-vc+vd
function roundoff(amount) {
return Math.round(amount)
function decimal(num){
var tempnum=num
for (i=0;i<tempnum.length;i++){
if (tempnum.charAt(i)=="."){
break
}
if (tempnum.charAt(tempnum.length-2)=="."){
num=tempnum+"0"
}
else{
num=tempnum
}
var result=Math.round(num*100)/100};
}
}
}
}
//-->
</SCRIPT>
Many thanks,
Eski
From looking at the tutorial at http://www.javascriptkit.com/javatutors/round.shtml
I added "var result=Math.round(tempnum*100)/100000}"
to the final line of my page, but it does not work!!
<SCRIPT LANGUAGE="JavaScript">
<!--
function calc(f)
{
vx = parseInt(f.x.value);
da = new Date(f.a.value);
db = new Date(f.b.value);
dd = (db.valueOf()-da.valueOf())/1000/60/60/24;
vc = parseInt(f.c.value);
vd = parseInt(f.d.value);
f.answer.value=(vx/365)*dd-vc+vd
function roundoff(amount) {
return Math.round(amount)
function decimal(num){
var tempnum=num
for (i=0;i<tempnum.length;i++){
if (tempnum.charAt(i)=="."){
break
}
if (tempnum.charAt(tempnum.length-2)=="."){
num=tempnum+"0"
}
else{
num=tempnum
}
var result=Math.round(num*100)/100};
}
}
}
}
//-->
</SCRIPT>
Many thanks,
Eski