Colton Idle
12/04/2021, 8:05 PMfun Long.euroCentsToString(): String {
val format = NumberFormat.getCurrencyInstance()
format.maximumFractionDigits = 2
format.currency = Currency.getInstance("EUR")
return format.format(this/100)
}
If I call 849999L.euroCentsToString()
I get a result of €8,499.00
I thought what I'd get is €8.499,99
So Basically three issues:
1. I thought europeans use .
to separate thousands from hundreds
2. I thought europeans use ,
to designate the start of fractional (cents)
3. I thought I'd see 99 as the cents and not 00.TwoClocks
12/04/2021, 8:07 PMColton Idle
12/04/2021, 8:11 PM8.499,00 €
the trailing euro symbol is interesting, but it proves your point.TwoClocks
12/04/2021, 8:11 PMthis
?Colton Idle
12/04/2021, 8:12 PMTwoClocks
12/04/2021, 8:12 PMColton Idle
12/04/2021, 8:13 PMTwoClocks
12/04/2021, 8:14 PMColton Idle
12/04/2021, 8:14 PMephemient
12/04/2021, 8:15 PMColton Idle
12/04/2021, 8:15 PMTwoClocks
12/04/2021, 8:16 PMColton Idle
12/04/2021, 8:19 PMreturn format.format(this/100.0)
fixed it. So I needed the 100.0 not 100TwoClocks
12/04/2021, 8:19 PMephemient
12/04/2021, 8:20 PMTwoClocks
12/04/2021, 8:20 PMephemient
12/04/2021, 8:20 PMColton Idle
12/04/2021, 8:20 PMephemient
12/04/2021, 8:24 PMBigDecimal(599L.toBigInteger(), 2) == BigDecimal("5.99")
BigDecimal is exact, the scaling is done on powers of 10. it feels like overkill but there isn't another fixed point number type built inTwoClocks
12/04/2021, 8:25 PMColton Idle
12/04/2021, 8:28 PMTwoClocks
12/04/2021, 8:29 PMephemient
12/04/2021, 8:29 PMNumberFormat.getCurrencyInstance(Locale.ITALY).format(BigDecimal(849999L.toBigInteger(), 2)) == "8.499,99 €"
NumberFormat.getCurrencyInstance(Locale.forLanguageTag("it-IT-u-cu-USD")).format(BigDecimal(849999L.toBigInteger(), 2)) == "8.499,99 USD"
NumberFormat.getCurrencyInstance(Locale.forLanguageTag("en-US-u-cu-EUR")).format(BigDecimal(849999L.toBigInteger(), 2)) == "€8,499.99"
Colton Idle
12/04/2021, 8:29 PMfun Long.centsToString(): String {
val format = NumberFormat.getCurrencyInstance(Locale.ITALY)
format.maximumFractionDigits = 2
format.currency = Currency.getInstance("EUR")
return format.format(BigDecimal(this).divide(BigDecimal(100.0)))
}
TwoClocks
12/04/2021, 8:30 PMephemient
12/04/2021, 8:30 PMColton Idle
12/04/2021, 8:32 PMtoBigInteger
) was unexpected to me thofun Long.centsToString(): String {
val format = NumberFormat.getCurrencyInstance(Locale.ITALY)
format.currency = Currency.getInstance("EUR")
return format.format(BigDecimal(this.toBigInteger(), 2))
}
Ended up with this now.ephemient
12/04/2021, 8:33 PMColton Idle
12/04/2021, 8:34 PMephemient
12/04/2021, 8:35 PM