Metoden Math.floor
Metoden Math.floor avrundar
ett tal till heltal alltid nedåt.
Syntax
javascriptMath.floor(tal);
Exempel
Låt oss avrunda talet 2.9999 nedåt:
javascriptconsole.log(Math.floor(2.9999));
Resultatet av att köra koden:
javascript2
Se även
-
metoden
Math.ceil,
som utför avrundning av ett tal uppåt -
metoden
Math.round,
som också avrundar ett tal till heltal -
metoderna
toFixedochtoPrecision,
som utför avrundning av ett tal till ett angivet antal decimaler