toFixed does not work!
alternative function to fix toFixed rounding problems
by Domenico Sgarbossa
JavaScript
function fixTo(val, places,rounding) {
(rounding != 'floor' && rounding != 'ceil') ? rounding = 'round' : rounding = rounding;
var result, num = val, multiplier = Math.pow( 10,places );
result = Math[rounding](num * multiplier) / multiplier;
return Number( result );
}
alert('valore iniziale: 120.175, aprrossimato con toFixed: '+Number(120.175).toFixed(2)+' approssimato con fixTo: '+fixTo(120.175,2));