469,917 Members | 1,891 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,917 developers. It's quick & easy.

Negative Numbers in Mozilla

Hi,

I have a bit of code which draws a chart up or down from the centre line
(zero).

When I have negative numbers in MSIE it displays fine and in Mozila it
doesn't draw at all.

Positve numbers draw without problems.

Anybody any ideas.

TIA
This calls the function to draw

histchart(-5.3,3)

This is my external jsfile

colr = new Array()
colr[3] ='#FEC9BC'
colr[5] ='#OOCC33'
colr[10] ='#3780C8'

function histchart(change,col)
{
colour = colr[col]
change = parseInt(10*parseFloat(change))/10

if(change<0)
{
scale = 10
document.write("<table width='100%' height='100%' border='0'
cellpadding='0' cellspacing='0'><tr><td height='70%' align='center'
valign='bottom' class=p7a>" + change +"</td></tr><tr><td height='1'
bgcolor='#000000'></td></tr><tr><td height='50%' valign='top'><div
align='center'><table width='15' height=" + parseInt(scale*Math.abs(change))
+ "% border='0' cellpadding='0' cellspacing='0' bgcolor=" + colour +
"><tr><td></td></tr></table></div></td></tr></table>")

}
else
{
scale = 5
document.write("<table width='100%' height='100%' border='0'
cellpadding='0' cellspacing='0'><tr><td height='70%' align='center'
valign='bottom'><table width='15' height='100%' border='0' cellpadding='0'
cellspacing='0'><tr><td></td></tr><tr><td height=" + parseInt(scale*change)
+ "% bgcolor=" + colour + "></td></tr></table></td></tr><tr><td height='1'
bgcolor='#000000'></td></tr><tr><td height='50%' valign='top'><div
align='center' class=p7a>+" + change + "</div></td></tr></table>")

}
}
Jul 23 '05 #1
1 1338
Lee
Iain West said:

Hi,

I have a bit of code which draws a chart up or down from the centre line
(zero).

When I have negative numbers in MSIE it displays fine and in Mozila it
doesn't draw at all.

scale = 10
document.write("<table width='100%' height='100%' border='0'
cellpadding='0' cellspacing='0'><tr><td height='70%' align='center'
valign='bottom' class=p7a>" + change +"</td></tr><tr><td height='1'
bgcolor='#000000'></td></tr><tr><td height='50%' valign='top'><div
align='center'><table width='15' height=" + parseInt(scale*Math.abs(change))
+ "% border='0' cellpadding='0' cellspacing='0' bgcolor=" + colour +
"><tr><td></td></tr></table></div></td></tr></table>")


You shouldn't be using parseInt with numerical arguments.

It takes a string as an argument, so it's converting the number to
a string and then parsing the integer value out of that string.
Netscape converts numbers between (-1,1) to strings beginning
with a decimal point. Such strings cannot be parsed by parseInt.

Use Math.round() or Math.floor(), depending on your needs.

Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.