Announcement

Collapse
No announcement yet.

Explain this please

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Explain this please

    Silly question, but it has me befuddled. What is wrong with the following code?

    prevclos = close(0,1,"us #f,d");
    todopen = open(1,1,"us #f,d");
    gap = (Math.abs(todopen-prevclos)>.49) ? true : false;
    bstop = prevclos +.5;
    sstop = prevclos - .5;
    debugPrintln ("bstop: "+bstop+" sstop: "+sstop);


    prevclos returns 106.969
    sstop returns 106.469 as you would expect, but
    bstop, instead of being 107.469 is 106.9690.5

    So it seems as if I have some type mismatch, but where was it introduced? There are no other lines in the program as of yet - other than main() { and }

  • #2
    I see a few things, the top two are:

    If you want the previous close use -1, not 1
    same with open.

    It seems that it is viewing prevclos as a string. Since there is no - opperation associated with a string it converts it to int and does the right thing. However there is a + associated with strings...and that concat's the two strings together.

    Try:
    parseFloat(string) ie: parseFloat(prevclos);

    to convert before the add.

    Garth
    Garth

    Comment


    • #3
      Hi Garth,

      I should have mentioned that the 0, 1 or -1 in the get statements were all irrelevant at this point. Sorry for the confusion. In any event the parseFloat function seems to do the trick.

      Thank you very much.

      Jamie

      Comment

      Working...
      X