[ Leksykon ] [ JavaScript ] [ Metody ] [ Właściwości ] [ Math() ]
Math.trunc()
[_] [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.trunc(1.22)); // 1
console.log(Math.trunc(12.13)); // 12
console.log(Math.trunc(0.12345)); // 0
console.log(Math.trunc(-0.12345)); // -0
console.log(Math.trunc("-5.123")); // -5
console.log(Math.trunc(-0)); // -0
console.log(Math.trunc(0)); // 0
console.log(Math.trunc(-Infinity)); // -Infinity
console.log(Math.trunc(Infinity)); // Infinity
console.log(~(5.5)); // -6
console.log(~(-6)); // 5
console.log(~~(5.5)); // 5
console.log(~~(-5.5)); // -5
console.log(Math.trunc(5.5)); // 5
console.log(Math.trunc(-6)); // -6
console.log(Math.trunc(5.5)); // 5
console.log(Math.trunc(-5.5)); // -5
console.log(Math.floor(5.5)); // 5
console.log(Math.floor(-6)); // -6
console.log(Math.floor(5.5)); // 5
console.log(Math.floor(-5.5)); // -6
Opis:
Metoda Math.trunc() statyczna zwraca część całkowitą liczby, usuwając wszelkie cyfry ułamkowe. Parametr liczba. Zwracana wartość część całkowita parametru.
Linki:
Math.abs()
Math.ceil()
Math.floor()
Math.round()
Math.sign()