Click to See Complete Forum and Search --> : toFixed on a Mac


thellama
03-27-2003, 05:05 AM
Hello,

If anyone can help I would appreciate this....as its a real hair pulling out experience!!!!

I'm having trouble getting this to work on a mac (latest version of IE on OS9):

function calc()
{
if ((document.performance.turnover_last_year.value <= 0) || (document.performance.total_spend.value <= 0))
document.performance.share.value = "0.00%";
else
$shared = (document.performance.turnover_last_year.value / document.performance.total_spend.value) * 100;
document.performance.share.value = $shared.toFixed(2) + "%";
}

but it works on IE6 on a PC!!!!!!

Once again if anyone can help I would appreciate it!!

Thanks

Steve

thellama
03-27-2003, 06:28 AM
sorry about this!.....

this is my test script(below)....does any know why it would say "object dosent support this property or method"????

Thanks again

Steve


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
<!--
var $shared=0;
function calc()
{
if ((document.performance.turnover_last_year.value <= 0) || (document.performance.total_spend.value <= 0))
document.performance.share.value = "0.00%";
else
$shared = (document.performance.turnover_last_year.value / document.performance.total_spend.value) * 100;
document.performance.share.value = $shared.toFixed(2) + "%";
}
-->
</script>
<title>Untitled</title>
</head>

<body bgcolor="#CCCCCC" topmargin="0" leftmargin="0" onLoad="calc()" link="#000000" alink="#000000" vlink="#000000">
<form name="performance" action="update" method="POST">
<input type="text" name="total_spend"
value="52.4567"
onBlur="calc(this.form)">

<input type="text" name="turnover_last_year"
value="53.889"
onBlur="calc()">


<input type="text" name="share" value="0.00%" disabled>
</form>



</body>
</html>

thellama
03-27-2003, 06:36 AM
Thanks I'll give that a try!!!!

why would it work in IE6 on a PC?????...just curious sorry!

thanks again

thellama
03-27-2003, 06:48 AM
Hi again!!!

Youve solved it!!!!!!!!!

thanks it appears to be the fact that macs cant do toFixed!!!!!

by testing....

var $shared=0;
var nbr = Number($shared);
if (isNaN(nbr)) {
alert("Not a number!");
} else {
alert("number");
nbr = nbr.toFixed(2);
}

which brings back "number" in a pop up and an error on toFixed on the mac!!!!!!

and....


function calc()
{
if ((document.performance.turnover_last_year.value <= 0) || (document.performance.total_spend.value <= 0))
document.performance.share.value = "0.00%";
else
$shared = (document.performance.turnover_last_year.value / document.performance.total_spend.value) * 100;
document.performance.share.value = $shared + "%";
}


brings back a result not rounded up !!!!!!!


thanks again....but one final thing do you know of a site or some code which would do the function another way for the mac????

Steve

thellama
03-27-2003, 08:03 AM
Thanks

It might be useful to note for anyone else that toFixed dosent work in ie 5 and below, but this script works in older browsers as well

it looked like this in the end....



<SCRIPT LANGUAGE="JavaScript">
<!--
var $shared=0;
var nbr = Number($shared);
if (isNaN(nbr)) {
alert("Not a number!");
} else {
alert("number");
nbr = nbr.toFixed(2);
}
function round(number,X) {
// rounds number to X decimal places, defaults to 2
X = (!X ? 2 : X);
return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}
function calc()
{
if ((document.performance.turnover_last_year.value <= 0) || (document.performance.total_spend.value <= 0))
document.performance.share.value = "0.00%";
else
$shared = (document.performance.turnover_last_year.value / document.performance.total_spend.value) * 100;
document.performance.share.value = ( round($shared) + "%");

}
-->
</script>



Steve

thellama
03-28-2003, 04:00 AM
Hi...

Cool, I didnt notice that!!!! I'll give that a try!

...but saying that the code I ended up with achieved the result....a bit messy though!...If I've got time I'll implement your suggestion as its a lot cleaner than mine...thanks once again!

Cheers

Steve