Negative Numbers in Mozilla

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Iain West

    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(chang e,col)
    {
    colour = colr[col]
    change = parseInt(10*par seFloat(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='#00000 0'></td></tr><tr><td height='50%' valign='top'><d iv
    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='#00000 0'></td></tr><tr><td height='50%' valign='top'><d iv
    align='center' class=p7a>+" + change + "</div></td></tr></table>")

    }
    }


  • Lee

    #2
    Re: Negative Numbers in Mozilla

    Iain West said:[color=blue]
    >
    >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='#0000 00'></td></tr><tr><td height='50%' valign='top'><d iv
    >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>")[/color]

    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.

    Comment

    Working...