Change Duration.toString(unit, decimals) formatting

- switch to scientific notation when value is too big (greater than 1e14)
- allow at most 12 decimals, larger values are coerced to 12
- use scientific format with exactly two decimals in mantissa in JVM
This commit is contained in:
Ilya Gorbunov
2019-06-17 04:46:24 +03:00
parent 5cf7c7e5bf
commit a5b7c270ae
3 changed files with 13 additions and 8 deletions
@@ -34,4 +34,4 @@ internal actual fun formatUpToDecimals(value: Double, decimals: Int): String =
private val scientificFormat = ThreadLocal<DecimalFormat>()
internal actual fun formatScientific(value: Double): String =
scientificFormat.getOrSet { DecimalFormat("0E0", rootFormatSymbols).apply { maximumFractionDigits = 2 } }.format(value)
scientificFormat.getOrSet { DecimalFormat("0E0", rootFormatSymbols).apply { minimumFractionDigits = 2 } }.format(value)