[ Leksykon ] [ JavaScript ] [ Metody ] [ Właściwości ] [ Math() ]
Math.round()
[_] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z]
Przykłady:
console.log(Math.round(0.99)); // 1
console.log(Math.round(1.95), Math.round(1.5), Math.round(1.05)); // 2 2 1
console.log(Math.round(-1.05), Math.round(-1.5), Math.round(-1.95)); // -1 -1 -2
console.log(Math.round(-Infinity)); // -Infinity
console.log(Math.round(Infinity)); // Infinity
console.log(Math.round(-1.51)); // -2
console.log(Math.round(-1.5)); // -1
console.log(Math.round(-0.1)); // -0
console.log(Math.round(0)); // 0
console.log(Math.round(1.49)); // 1
console.log(Math.round(1.5)); // 2
Opis:
Metoda Math.round() statyczna zwraca wartość liczby zaokrągloną do najbliższej liczby całkowitej. Parametr Liczba. Zwracana wartość zaokrąglona do najbliższej liczby całkowitej. Jeśli ułamkowa część argumentu jest większa niż 0,5, argument jest zaokrąglany do liczby całkowitej z następną wyższą wartością bezwzględną. Jeśli jest mniejsza niż 0,5, argument jest zaokrąglany do liczby całkowitej z niższą wartością bezwzględną. Jeśli część ułamkowa wynosi dokładnie 0,5, argument jest zaokrąglany do najbliższej liczby całkowitej w kierunku +∞.
Linki:
Math.abs()
Math.ceil()
Math.floor()
Math.sign()
Math.trunc()
Number.prototype.toPrecision()
Number.prototype.toFixed()