Utilisation de la bibliothèque suivante: http://jsfromhell.com/classes/bignumberentier Big n'est pas arrondi
mon grand entier n'est pas arrondi.
Mon code est le suivant:
x=1234.56;
y = new BigNumber(x);
document.write("<br>1 "+Math.round(x) +"<br>");
document.write("<br>2 "+y.round()+"<br>"); // '1235'
document.write("<br>3 "+y.round(1)+"<br>"); // '1235.6'
document.write("<br>4 "+y.round(2)+"<br>"); // '1235.56'
document.write("<br>5 "+y.round(10)+"<br>"); // '1235.56'
document.write("<br>6 "+y.round(0, 1)+"<br>"); // '1234'
document.write("<br>7 "+y.round(0, 6)+"<br>"); // '1235'
document.write("<br>8 "+y.round(1, 1)+"<br>"); // '1234.5'
document.write("<br>9 "+y.round(1, BigNumber.ROUND_HALF_EVEN)+"<br>"); // '1234.6'
Je reçois la sortie suivante:
2 1234,56
3 1234,56
4 1234,56
5 1234,56
6 1234,56
7 1234,56
8 1234,56
9 1234,56
@JonathanM Il existe une méthode '.round()' [ici] (http: //mikemcl.github. io/bignumber.js/# round) –
@JonathanM vous ne regardez que les méthodes de classe, pas les méthodes d'instance. –
Désolé, j'ai les yeux croisés. :) –