John O'Reilly
java.text.NumberFormat
eygraber
java.text.DecimalFormat
jw
Call out to Intl, presumably
import js.intl.NumberFormat
private 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) }
A modern programming language that makes developers happier.