Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Teste Truncar numero
(version: 0)
Comparing performance of:
toFixed vs Round vs floor vs Bitwise vs Math.trunc
Created:
2 years ago
by:
Guest
Jump to the latest result
Tests:
toFixed
let numero = 123.45678; let resultado = numero.toFixed(2); // "123.46" como string resultado = Number(resultado); // Converte de volta para número, se necessário
Round
let numero = 123.45678; let resultado = Math.round(numero * 100) / 100; // 123.46
floor
let numero = 123.45678; let resultado = Math.floor(numero * 100) / 100; // 123.45
Bitwise
let numero = 123.45678; let resultado = (numero * 100 | 0) / 100; // 123.45
Math.trunc
let numero = 123.45678; let resultado = Math.trunc(numero * 100) / 100; // 123.45
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
toFixed
Round
floor
Bitwise
Math.trunc
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36
Browser/OS:
Chrome Mobile 120 on Android
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
toFixed
229651.9 Ops/sec
Round
705876.2 Ops/sec
floor
700182.2 Ops/sec
Bitwise
149503312.0 Ops/sec
Math.trunc
712237.8 Ops/sec
Related benchmarks:
trunc-benchmark
trunc-benchmark
trunc-benchmark
Decimal rounding
Comments
Confirm delete:
Do you really want to delete benchmark?