Is there an easy way to read back if the language set uses a decimal comma or a decimal point?
And in countries where a point is used as a decimal separator, a comma is usually used to separate thousands. So, for example, twelve thousand five hundred with a decimal of five zero is written differently depending on the country: In the USA, Mexico, or the UK, it would be written: 12 500.50 or 12,500.50.
In English-speaking countries, the decimal point is usually a small dot (.) placed either on the baseline or halfway between the baseline and the top of the digits In many other countries, the radix point is a comma (,) placed on the baseline.
And in countries where a point is used as a decimal separator, a comma is usually used to separate thousands. So, for example, twelve thousand five hundred with a decimal of five zero is written differently depending on the country: In the USA, Mexico, or the UK, it would be written: 12 500.50 or 12,500.50.
In the United States, we use the decimal or period (“.”) to represent the difference between whole numbers and partial numbers. We use the comma (“,”) to separate groups of three places on the whole numbers side. This might be different from the way you currently write numbers.
EDIT: Updating based on @Algar's suggestion; you can directly use:
char separatorChar = DecimalFormatSymbols.getInstance().getDecimalSeparator();
As it will always return an instance of DecimalFormatSymbols
.
NumberFormat nf = NumberFormat.getInstance(); if (nf instanceof DecimalFormat) { DecimalFormatSymbols sym = ((DecimalFormat) nf).getDecimalFormatSymbols(); char decSeparator = sym.getDecimalSeparator(); }
Docs:
NumberFormat
, DecimalFormat
, DecimalFormatSymbols
According to the DecimalFormat docs, apparently calling NumberFormat.getInstance() is safe, but may return a subclass other than DecimalFormat (the other option I see is ChoiceFormat). I believe for the majority of instances it should be a DecimalFormat, and then you can compare decSeparator
against a ,
and .
to see which format it is using.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With