• I think you don't have to format the currentkWh on the puck.

    Just use toFixed on the display page. For example:

    var kwh = 1234.56789;
    console.log(kwh.toFixed(2))
    "1234.57"
    

    Separation of data & display concerns :)

  • The result of toFixed looks like a number, because you console.log it, so there are no parenthesis around the printed value.

    >var fixed = kwh.toFixed(2);
    ="1234.50"
    
    >typeof fixed
    ="string"
    

    And yes, looks like some rounding anomaly:

    >2134.506.toFixed(2)
    ="2134.50"
    >2134.507.toFixed(2)
    ="2134.51"
    
About

Avatar for Robin @Robin started