Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decimal point or decimal comma in Android

Tags:

Is there an easy way to read back if the language set uses a decimal comma or a decimal point?

like image 597
patrick Avatar asked Nov 18 '11 19:11

patrick


People also ask

What is the difference between decimal comma and 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.

Do you use comma or dot for decimals?

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.

Can a decimal have a comma?

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.

What does a comma in a decimal mean?

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.


1 Answers

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.

like image 158
Kevin Coppock Avatar answered Oct 05 '22 03:10

Kevin Coppock