How to format a number into a specified length in nodejs

i have a value 12.3456789, and i need result like 12.34.

I tried toPrecision() method and got following error.

Object 3.0 has no method 'toPrecision' 

Tried code is,

var ERA = stat['stat_group']['earned_run_average']  
statsHash['earned_run_average'] = ERA.toPrecision(4);

For javascript you can try,

if ERA is of type string first convert it to number ERA = 1 * ERA, then

statsHash['earned_run_average'] = 1 * ERA.toFixed(2);

hope this helps.

function round(value, precision)
{ 
    precision = Math.pow(10,precision);
    return Math.round( value * precision ) / precision;
}