Kotlin / kotlinx-benchmark

Kotlin multiplatform benchmarking toolkit
Apache License 2.0
499 stars 40 forks source link

format numbers with a fixed Locale #200

Closed adam-enko closed 5 months ago

adam-enko commented 5 months ago

Decimal/thousands separators differ per Locale. Using the default system Locale causes FormatTests failures when the default system Locale has , for the decimal separator and . as the thousands separator (which is common in Europe).

E.g.

Expected :83.3333 ops/us
Actual   :83,3333 ops/us
image
qurbonzoda commented 5 months ago

Related discussion in JMH mailing list: https://mail.openjdk.org/pipermail/jmh-dev/2016-September/002344.html

adam-enko commented 5 months ago

Does the tests fail in JS and WasmJs as well? Double.format seems to use the host default locale in those targets.

On my machine, they both pass. It was only the JVM ones that failed.

adam-enko commented 5 months ago

Agree with both comments. It seems like there's no direct replacement for Locale.ROOT in the JS implementation, so perhaps makes sense to use some fixated locale that conforms the requirements

So you mean, instead of d.toLocaleString(undefined, { ... } ), instead specify a locale with the separators we want? E.g. d.toLocaleString('en-GB', { ... } )

ALikhachev commented 5 months ago

So you mean, instead of d.toLocaleString(undefined, { ... } ), instead specify a locale with the separators we want? E.g. d.toLocaleString('en-GB', { ... } )

Yes