'Change decimal seperator locale in Android string resource

I want to display some coördinates in my Android app. I receive two double values (lat and long in decimal degrees notation) from my backend.

Example data:

var lat : Double = 52.5027
var long : Double = 5.41982

Now i fill my textView in my class file:

tvLat.text = getString(R.string.gps_format, lat)
tvLong.text = getString(R.string.gps_format, lat)

and my xml resource file contains this:

<string name="gps_format">%,.5f&#176;</string>

It displays:

52,50270°
5,41982°

As I live in the Netherlands it is formatted accordingly.

See https://developer.android.com/reference/java/util/Formatter

Number Localization Algorithm

  1. ...
  2. If a decimal separator is present, a locale-specific decimal separator is substituted.

We typically use a , as a decimal separator, and . as a group separator in the Netherlands.

Question:

  • Is there an international standard for the notation of coördinates in decimal degrees which requires the decimal seperator to be .?
  • If there is, or I just want to, how do I achieve this without changing my locale or formatting for the entire app?

Desired output:

52.50270°
5.41982°

I have not found a way yet for the XML, so my guess is that it will have to be done with code. I've looked into the setDecimalSeparator method, but I can't get any working solution.



Solution 1:[1]

I've found something which could be called a dirty solution.

tvLat.text =
    getString(R.string.gps_format,
        DecimalFormat(
            "0.00000",
            DecimalFormatSymbols(Locale.getDefault())
                .apply { decimalSeparator = '.' }
        ).format(lat).toString()
    )

Along with a change in my resource file

<string name="gps_format">%s&#176;</string>

New output:

52.50270°
5.41982°

I would like to have the format in my string resource though. Anyone has suggestions?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1