android十进制格式为阿拉伯语,符号在数字的右侧 [英] android decimalformat for arabic, symbol is on right side of number
问题描述
我正在尝试支持左语言的RTL,并且正在测试阿拉伯语(对此我一无所知).
I'm trying to support RTL to left languages, and I'm testing with Arabic (which I know nothing about).
负/正符号应该位于数字的右侧还是左侧?我认为应该在左侧,但是当我使用Android的DecimalFormat将数字放入设备设置的语言环境中时,该符号会显示在右侧.
Is the negative/positive symbol supposed to be on the right or left of the number? I think it's supposed to be on the left, but when I use Android's DecimalFormat to put the number in the locale the device is set to, the symbol appears on the right..
有人遇到过这种情况,知道如何解决吗?我能想到的最好是,如果它为负数,则用括号将其打印出来,应该可以解决这个问题,但不是理想的选择.
Has anyone encountered this, know how to work around it? Best I can think is to print it with parentheses if it's negative, that should get around this but isnt ideal.
编辑
对不起,代码总是有帮助的.如果我打印以下内容(经度为负):
Sorry, code always helps. If I print the below (and the longitude is negative):
DecimalFormat coord_df = new DecimalFormat("#.000000");
coord_df.format(loc.getLongitude())
它是这样印刷的
##,######-
其中#号是阿拉伯数字(例如此处的阿拉伯东部行显示的数字): http://en.wikipedia.org/wiki/Eastern_Arabic_numerals )
where the # signs are numbers in arabic (like those shown on the eastern arabic row here: http://en.wikipedia.org/wiki/Eastern_Arabic_numerals)
我需要在数字的正确边上得到负数(我相信这是左边)
I need to get the negative on the correct side of the number (which is the left I believe)
解决方案
我最终只是在需要弄乱显示数字(如答案)时检查设备是否处于RTL中:
I ended up just checking whether the device was in RTL whenever I needed to mess with displaying numbers like the answer here: android determine if device is in right to left language/layout
如果设备是RTL,则我使用带有负号的负子模式作为后缀,如下所示:
If the device is RTL then I use a negative subpattern with a negative sign as a suffix like this:
"#.000000,#.000000-"
推荐答案
只需共享另一种方法,即可在文本视图中将文本方向设置为从左到右",它将正确显示负号.
Just sharing another approach, in your text views you can set the text direction to Left to Right, it will shows the negative sign correctly.
textView.setTextDirection(TextView.TEXT_DIRECTION_LTR);
这篇关于android十进制格式为阿拉伯语,符号在数字的右侧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!