Skip to content

Commit 608f6d3

Browse files
committed
format numbers with a fixed Locale
Decimal/thousands separators differ per Locale. Using the default system Locale causes test failures when `,` is used as 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 ```
1 parent fa82bd2 commit 608f6d3

File tree

1 file changed

+5
-4
lines changed
  • runtime/jvmMain/src/kotlinx/benchmark

1 file changed

+5
-4
lines changed
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package kotlinx.benchmark
22

3-
import java.io.*
3+
import java.io.File
4+
import java.util.*
45

56
internal actual fun Double.format(precision: Int, useGrouping: Boolean): String {
6-
return if (useGrouping) "%,.0${precision}f".format(this)
7-
else "%.0${precision}f".format(this)
7+
return if (useGrouping) "%,.0${precision}f".format(Locale.ROOT, this)
8+
else "%.0${precision}f".format(Locale.ROOT, this)
89
}
910

1011
internal actual fun String.readFile(): String {
@@ -15,4 +16,4 @@ internal actual fun String.writeFile(text: String) {
1516
File(this).writeText(text)
1617
}
1718

18-
internal actual inline fun measureNanoseconds(block: () -> Unit): Long = TODO("Not implemented for this platform")
19+
internal actual inline fun measureNanoseconds(block: () -> Unit): Long = TODO("Not implemented for this platform")

0 commit comments

Comments
 (0)