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