Repository navigation
Invalid separator #465
|
While testing the library, I notice that it always uses a '.', whereas in some languages (such as French), it should be a ',' |
Replies: 1 comment
|
That's intentional rather than a bug. The unit formatting in spatial-k is locale-independent on purpose:
So it's best to treat // JVM / Android
import java.text.NumberFormat
import java.util.Locale
import org.maplibre.spatialk.units.catalog.Metric.Kilometers
val km = distance.toDouble(Kilometers)
val nf = NumberFormat.getNumberInstance(Locale.FRANCE).apply {
minimumFractionDigits = 2
maximumFractionDigits = 2
}
val label = "${nf.format(km)} ${Kilometers.symbol}" // "12,35 km"In a multiplatform project you can wrap that in an If you only need French and want something quick in common code, |
That's intentional rather than a bug. The unit formatting in spatial-k is locale-independent on purpose:
format()writes exactly whatparse()/parseOrNull()reads back, and the parser only accepts.as the decimal separator. The KDoc onLengthFormatspells it out: "A comma is never a decimal separator."LengthFormat.Osmfor OpenStreetMap tags, where3.5 mis valid and3,5 misn't.So it's best to treat
toString()/format()as a stable, round-trippable repre…