JavaScript 04-03-2013

Javascript.png

Come arrotondare un numero

Inserire il seguente codice in una funzione javascript:


1
2
3
4
5
6
7
function arrotonda(numero, posDecimali){

var numeroArrotondato = Math.round(numero * Math.pow(10, posDecimali)) / Math.pow(10, posDecimali);

return numeroArrotondato;

}
 
var numeroArrotondato = arrotonda(10.5340502, 2);
alert(numeroArrotondato);


Ti potrebbe interessare anche JavaScript | Arrotonda