Decimal format in a multi-platform build


#1

I am trying to converting one of my JavaFX projects to a multi-platform one. Since I do not have any experience with javascript ecosystem it is moving very slow.

One specific problem I encountered, that there seems to be no way to define a format for numbers in common library. All I need is to limit floating point precision in the output to 2 digits. The problem is that both common and js do not have either String.fotmat or DecimalFormat, so I am not sure how to do it. For now, I declared an expected tooling function, which in JS returns number as-is, but it is not a solution.

Any suggestions?


#2

In Javascript, you have: Number.toFixed(decimalDigits: Int): String
You also have de Intl API that allows you to format numbers in different ways and for different cultures.


#3

Thanks for suggestion. In fact it should be num.asDynamic().toFixed(digits) as String (found the solution here).

I think it should be added to kotlin-common standard library.


#4

https://youtrack.jetbrains.com/issue/KT-21644


#5

Thanks, I’ve missed that. Though it is really hard to find something on youtrack if you do not know it is there.