Announcement

Collapse
No announcement yet.

How I get the right value output?

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

  • How I get the right value output?

    Hi,

    I use in the *.efs the

    getMostRecentAsk();
    getMostRecentBid();
    close();

    in an Adv.Chart from the german Bund-Future. The Bund Future is working with values like e.g. 116.01, 116.02, .... each tick is in the Bund-Future a increment of 0.01

    But somtimes I get in my *.efs a value (if I use formula output window) like 116.74000000000001 instead of the real 116.74

    What I have to do so it work proper?

    Torso

  • #2
    Hi Torso,

    Please see this post for an explanation. The easiest to use method to round the number is to

    var tmp = 116.74000000000001 ;

    tmp = tmp.toFixed(2); //this converts to a string

    -or-

    tmp = tmp.toFixed(2)*1; //this re-converts to a number

    Another way to round ...

    tmp = Math.round(tmp*100)/100; // this remains a number

    I hope this helps.

    Comment


    • #3
      thanks

      I used :


      tmp = tmp.toFixed(2)*1;

      thanks, it work fine

      Torso

      Comment


      • #4
        Hi Torso,

        You are most welcome.

        Comment


        • #5
          better way ?

          Hi Steve,

          give it a better way? now I use .toFixed(2)*1 on each target in my *.efs, also for my var tradeOpen, tradeClose, close().... it works.

          but can I define the .toFixed(2)*1 in the function preMain() once, that the *.efs is working the whole time with all values in a " .toFixed(2)*1 - modus " ?

          e.g. now from my *.efs in the function main:

          //trade open (market)
          tmp = getMostRecentAsk();
          tradeOpen = tmp.toFixed(2)*1;
          tradeOpenhour = date.getHours();
          tradeOpenminute = date.getMinutes();
          tradeOpensecond = date.getSeconds();

          //targets
          tmp = tradeOpen+target1*tickSize;
          target1 = tmp.toFixed(2)*1;
          tmp = tradeOpen+target2*tickSize;
          target2 = tmp.toFixed(2)*1;
          tmp = tradeOpen+target3*tickSize;
          target3 = tmp.toFixed(2)*1;
          tmp = tradeOpen+target4*tickSize;
          target4 = tmp.toFixed(2)*1;
          tmp = tradeOpen+target5*tickSize;
          target5 = tmp.toFixed(2)*1;
          tmp = tradeOpen+target6*tickSize;
          target6 = tmp.toFixed(2)*1;
          tmp = tradeOpen+target7*tickSize;
          target7 = tmp.toFixed(2)*1;



          Torso
          Last edited by Torso; 04-06-2006, 01:39 AM.

          Comment


          • #6
            Hi Torso,

            There is not any way that I am aware of to do this without creating a seperate function or object to handle all the rounding for you directly.

            Comment

            Working...
            X