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

查看:73
本文介绍了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天全站免登陆