Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Teste Truncar numero
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
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:
Chrome Mobile 120
Operating system:
Android
Device Platform:
Mobile
Date tested:
2 years ago
Bitwise
149.5M/s
Math.trunc
712K/s
Round
706K/s
floor
700K/s
toFixed
230K/s
View exact numbers
Test name
Executions per second
✓
Bitwise
149,503,312 Ops/sec
Math.trunc
712,238 Ops/sec
Round
705,876 Ops/sec
floor
700,182 Ops/sec
toFixed
229,652 Ops/sec
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