• Life happened so I put my project to the side for a couple of months. I decided to pick the project back up today and updated the firmware on the Espruino. By the way I really like the new GUI of the IDE :-)

    The issue I am having is toFixed(2) doesn't seem to get the decimal place to only two decimal places. toFixed(2) seemed to work before I took a break from my project.

    I hit the Send to Espruino button. I get the following output.

    _____ _ | |_ ___ ___ _ ||___ ___ | |_
    -| . | _| | | | | . | |
    || || |_|||_|_|

          |_| http://espruino.com  1v64 Copyright 2014 G.Williams
    

    echo(0);
    80.66461538461538793853833340108394622802734375 0
    161.403076923076923776534385979175567626953125 1
    241.99384615384616381561500020325183868408203125 2
    322.7323076923076996536110527813434600830078125 3
    403.54461538461538339106482453644275665283203125 4
    484.209230769230771329603157937526702880859375 5
    564.83362900747715684701688587665557861328125 6
    645.49824439209260162897408008575439453125 7
    726.0890136228617848246358335018157958984375 8
    806.62281160369502686080522835254669189453125 9 Temp: 80.662281160369502686080522835254669189453125
    =undefined

    CODE:

    function onInit() {
    
      function getResTempValue(x) {
        var temp=0;
        var avgTemp=0;
        for (var i=0;i<x;i++)
        {
          var vOut = E.getAnalogVRef() * analogRead(A0); // if you attached VOUT to Ao
          var vZero = 0.4;
          var tCoeff =  19.5 / 1000;
          var tempinc = (vOut - vZero) / tCoeff;
          var tempinf = tempinc * (9 / 5) + 32;
          temp = temp + tempinf;
          console.log(temp);
          console.log(i);
        }
        temp = temp / x;
        temp.toFixed(2);  //<-- Doesn't seem to work.
    
        console.log("Temp: " + temp);
        return temp;
      }
    
      getResTempValue(10);
    }
    
    onInit();
    
About

Avatar for d0773d @d0773d started