Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Intl.NumberFormat vs toLocalString vs string split & reduce (with fraction digits) vs toFixed
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Browser:
Chrome 130
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
toLocaleString
42882.0 Ops/sec
Intl.NumberFormat
38402.5 Ops/sec
string split & reduce
1838955.4 Ops/sec
toFixed
3950113.8 Ops/sec
Script Preparation code:
function pricize (num, decimal = 0) { const intPart = Math.floor(num) const intPieces = intPart.toString().split('') const len = intPieces.length const intStr = intPieces.reduce((result, chr, index, array) => { const pos = len - index result += (index !== 0 && pos % 3 === 0) ? ',' + chr : chr return result }, '') const decStr = decimal > 0 ? num.toFixed(decimal + 1).toString().slice(-(decimal + 2), -1) // toFixed() は四捨五入してしまうので(decimal + 1)桁まで求めて切り取る : '' return intStr + decStr } var target = 123456789.123456789 var options = {minimumFractionDigits: 3, maximumFractionDigits: 3}
Tests:
toLocaleString
var a = target.toLocaleString('en-US', options);
Intl.NumberFormat
var a = new Intl.NumberFormat('en-US', options).format(target)
string split & reduce
var a = pricize(target, 3)
toFixed
var a = target.toFixed(3)