Negative Numbers in Mozilla

I

Iain West

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>")

}
}
 
L

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top