Hello,
I am currently experimenting with Kotlin/js and I wanted to add thousand separators to some numbers. The best way seems to be to use JavaScript’s Number.toLocaleString() method.
I have not found a way to call it directly so I used the “js(…)” method to do so.
It looks like this:
fun Int.toLocaleString(): String {
@Suppress("UNUSED_VARIABLE")
val data = this
return js("data.toLocaleString()") as String
}
“data” gets marked as unused, so I had to suppress it.
My questions are:
- is there a way to call JavaScript’s native Number.toLocaleString() method?
- if not is there any sane way to implement the thousand separator?
- is there any way to let Kotlin know that the local variable “data” is not unused?
Thanks