Skip to content

Commit

Permalink
Fix number formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
rjaros committed May 29, 2024
1 parent ebd3bcb commit 1c78959
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/jsMain/kotlin/io/kvision/utils/NumberFormat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,6 @@ fun numberFormat(locales: String, optionsBuilder: NumberFormatOptions.() -> Unit
* Formats a number to fixed decimal digits without rounding.
*/
fun Number.toFixedNoRound(precision: Int): String {
val factor = 10.0.pow(precision)
return (floor(this.toDouble() * factor) / factor).toString()
val r = Regex("^-?\\d+(?:\\.\\d{0,$precision})?")
return r.find(this.toString())?.value ?: "0"
}

0 comments on commit 1c78959

Please sign in to comment.