Colton Idle
09/18/2023, 5:57 AMRonny Bräunlich
09/18/2023, 5:59 AMjava.text.NumberFormat
?Colton Idle
09/18/2023, 6:02 AMColton Idle
09/18/2023, 6:02 AMRonny Bräunlich
09/18/2023, 6:05 AMDouble
is enough you can do it like this:
val cents = 99 / 100.0
val currencyInstance = NumberFormat.getCurrencyInstance(<http://Locale.US|Locale.US>)
println(currencyInstance.format(cents))
Apart from this your solution looks fine to meArjan van Wieringen
09/18/2023, 6:38 AMascii
09/18/2023, 6:48 AMval left = 0.5f + 0.1f;
val right = 0.7f - 0.1f;
println("$left, $right, ${left == right}")
will print 0.6, 0.59999996, false
.Ruckus
09/18/2023, 6:56 AMRobert Williams
09/18/2023, 9:37 AMephemient
09/18/2023, 9:37 AMval cents = 99.toBigDecimal().scaleByPowerOfTen(-2)
NumberFormat.getCurrencyInstance(<http://Locale.US|Locale.US>).format(cents)
also works with no potential rounding (JVM only of course)Colton Idle
09/18/2023, 1:37 PMColton Idle
09/18/2023, 1:40 PM"#,##0.00",
needed. thanks all