John O'Reilly
02/25/2024, 10:10 PMjava.text.NumberFormat
when using Wasm based Compose for Web?eygraber
02/25/2024, 10:28 PMjava.text.DecimalFormat
. There's probably some API that could do something similar for java.text.NumberFormat
jw
02/25/2024, 11:30 PMJohn O'Reilly
02/26/2024, 11:59 AMCall out to Intl, presumablydo you mean through something like
import js.intl.NumberFormat
? That works in Kotlin/JS but not wasm I thinkjw
02/26/2024, 12:12 PMJohn O'Reilly
02/26/2024, 12:12 PMjw
02/26/2024, 12:22 PMJohn O'Reilly
02/26/2024, 12:30 PMprivate external object Intl {
class NumberFormat(locales: String, options: JsAny) {
fun format(l: Double): String
}
}
private fun formatPercentageOptions(): JsAny = js("({ style: 'percent', maximumFractionDigits: 2 })")
private fun formatAsUSDOptions(): JsAny = js("({ style: 'currency', currency: 'USD',})")
internal actual fun Double.formatPercentage(): String {
val format = Intl.NumberFormat(
locales = "en-US",
options = formatPercentageOptions(),
)
return format.format(this)
}
internal actual fun Double.formatDollarAmount(): String {
val format = Intl.NumberFormat(
locales = "en-US",
options = formatAsUSDOptions(),
)
return format.format(this)
}