Android将阿拉伯数字转换为英文数字 [英] Android convert Arabic number to English Number

查看:164
本文介绍了Android将阿拉伯数字转换为英文数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从gps收到以下错误:

I get the following error from the gps:

Fatal Exception: java.lang.NumberFormatException
Invalid double: "-٣٣٫٩٣٨٧٤"

现在这是由于我通过Fabric从用户那里得到的一个错误.它看起来像阿拉伯语,所以我猜只有在您设置了该语言或您的SIM卡时才会发生这种情况?是否可以强制GPS发送0-9范围内的字符?还是我可以通过某种方式解决此问题?

Now this is from a error that I got from a user via Fabric. It looks like arabic so I'm guessing it only happens if you have the language set to that, or your sim card? Is it possible to force the gps to send characters in the 0-9 range? Or can I somehow fix this?

推荐答案

尝试一下:

String number = arabicToDecimal("۴۲"); // number = 42;

private static final String arabic = "\u06f0\u06f1\u06f2\u06f3\u06f4\u06f5\u06f6\u06f7\u06f8\u06f9";
private static String arabicToDecimal(String number) {
    char[] chars = new char[number.length()];
    for(int i=0;i<number.length();i++) {
        char ch = number.charAt(i);
        if (ch >= 0x0660 && ch <= 0x0669)
           ch -= 0x0660 - '0';
        else if (ch >= 0x06f0 && ch <= 0x06F9)
           ch -= 0x06f0 - '0';
        chars[i] = ch;
    }
    return new String(chars);
}

这篇关于Android将阿拉伯数字转换为英文数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆