I needed to add the appropriate engineering notations (K, M, B, T) as per Locale for English and European lanuages. I figured that using NumberFormatter is suggested for Android API 30+.
I have implemented this function to do the conversion which works smooth for English and other EU languages except German which is very strange. I have tested against Spanish, French and Italian.
I need help in figuring out what could be the reason it is not working for German as it is highly important language for my case to support.
/**
* Converts Number to appropriate rounded off format with max 1 decimal place
* e.g. 1345 --> 1.3K, 15555900 --> 15.6M
*/
private fun formatCount(number: Long) = NumberFormatter.with()
.notation(Notation.compactShort())
.decimal(NumberFormatter.DecimalSeparatorDisplay.ALWAYS)
.precision(Precision.fixedFraction(1))
.locale(Resources.getSystem().configuration.locales.get(0))
.format(number)
.toString()
Maybe that is specific to the Language itself. For example, in German, I think, there is no representation of a thousand with a character like K. or even for ten thousand. Similarly in Japan, there is no representation for a thousand but there is for 10 thousand 万. Below are some examples
If you notice even though there are no characters added as a suffix to the number value but there is always a single-digit decimal. Which is the intention of your code. Only in Germany, the point(.) is reversed with a comma (,).