当区域设置设置为法语时 BlackBerry 的货币格式

发布于 2024-12-29 08:59:50 字数 69 浏览 0 评论 0原文

我正在编写一个需要法语支持的应用程序。当区域设置设置为 FR 时,我无法正确设置货币格式。有什么方法可以正确地做到这一点吗?

I've writing an app that requires French language support. I'm having trouble getting currency to format correctly when the locale is set to FR. Is there any way to do this correctly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼前雾蒙蒙 2025-01-05 08:59:50

我必须自己做。
使用以下方法创建了一个扩展 AFormatter 的“Formatter”类
现在不知道法国的情况如何,但在阿根廷我们使用以下格式 10.000.000,18 例如。
希望有帮助或者有人提供更好的解决方案

    public static String addCommas(String s) {
    int extraRound = 0;
    boolean negative = false;
    int c;
    if(s.charAt(0) == '-') {
        negative = true;
        s = s.substring(1);
    }
    int len = s.indexOf('.')==-1?s.length():s.indexOf('.');
    if(len > extraRound + 3) {
        c = len - extraRound  - 3;
        s = s.substring(0, c) + "," + s.substring(c);
    }

    if(len > extraRound + 6) {
        c = len - extraRound  - 6;
        s = s.substring(0, c) + "," + s.substring(c);
    }

    if(len > extraRound + 9) {
        c = len - extraRound  - 9;
        s = s.substring(0, c) + "," + s.substring(c);
    }

    if(len > extraRound + 12) {
        c = len - extraRound  - 12;
        s = s.substring(0, c) + "," + s.substring(c);
    }

    if(negative) {
        s = '-' + s;
    }
    return s;
}

public static String addCommasNew(String s) {
    int extraRound = 0;
    boolean negative = false;
    int c;
    if(s.charAt(0) == '-') {
        negative = true;
        s = s.substring(1);
    }
    int len = s.indexOf(',')==-1?s.length():s.indexOf(',');
    if(len > extraRound + 3) {
        c = len - extraRound  - 3;
        s = s.substring(0, c) + "." + s.substring(c);
    }

    if(len > extraRound + 6) {
        c = len - extraRound  - 6;
        s = s.substring(0, c) + "." + s.substring(c);
    }

    if(len > extraRound + 9) {
        c = len - extraRound  - 9;
        s = s.substring(0, c) + "." + s.substring(c);
    }

    if(len > extraRound + 12) {
        c = len - extraRound  - 12;
        s = s.substring(0, c) + "." + s.substring(c);
    }

    if(negative) {
        s = '-' + s;
    }
    return s;
}

public static String removeScientific(String s) {
    int eIndex = s.indexOf('E');
    int initialPos = s.indexOf('.');
    String result = s;

    if (eIndex != -1){
        int base = Integer.parseInt(s.substring(eIndex+1));
        String pre = s.substring(0, initialPos);
        String pos = s.substring(initialPos+1, eIndex);
        String pos1 = ""; 
        if (base < pos.length()){
            String pos1a = pos.substring(0, base);
            String pos1b = pos.substring(base, pos.length());
            pos1 = pos1a + "." + pos1b; 
        } else {
            pos1 = pos.substring(0, pos.length());
            for (int i = 0; i < base-pos.length(); i++){
                pos1 = pos1 + "0";
            }
        } 
        result = pre + pos1;
    } 

    return result;
}

public static String changePointToComma(String s){
    int initialPos = s.indexOf('.');
    String result = s;
    if (initialPos != -1){
        result = s.substring(0, initialPos) + "," + s.substring(initialPos + 1, s.length());
    }

    return result;
}

public static String changeCommaToPoint(String s){
    int initialPos = s.indexOf(',');
    String result = s;
    if (initialPos != -1){
        result = s.substring(0, initialPos) + "." + s.substring(initialPos + 1, s.length());
    }

    return result;
}

public static String removeNumberFormat(String s){
    int initialPos = s.indexOf('.');
    String result = s;
    if (initialPos != -1){
        result = s.substring(0, initialPos) + s.substring(initialPos + 1, s.length());
        result = Formatter.removeNumberFormat(result);
    } else {
        return result = Formatter.changeCommaToPoint(s);
    }

    return result;
}

public static String roundDouble(String s, int presicion){
    int initialPos = s.indexOf('.');
    String result = s;
    String pre;
    String pos;

    if (initialPos != -1){
        pre = s.substring(0, initialPos);
        pos = s.substring(initialPos + 1, s.length());
        if (presicion < pos.length()){
            pos = s.substring(initialPos + 1, initialPos + 1 + presicion );
            int dec = Integer.parseInt(pos);
            int next = Integer.parseInt(s.substring(initialPos + 1 + presicion, initialPos + 2 + presicion )); //to round the las digit
            if (next > 4){
                dec = dec + 1;
                pos = dec + "";
                if ((dec+"").length() > presicion){
                    pre = (Integer.parseInt(pre) + 1) + "";
                    pos = "0";
                }
            }
        } else {
        }

        result = pre + "." + pos; 
    }

    return result;
}

I had to do it myself.
Created a "Formatter" class extending AFormatter with the following methods
Don't now how it is in France but in Argentina we use the following format 10.000.000,18 for example.
Hope it's helps or that someone provides a better solution

    public static String addCommas(String s) {
    int extraRound = 0;
    boolean negative = false;
    int c;
    if(s.charAt(0) == '-') {
        negative = true;
        s = s.substring(1);
    }
    int len = s.indexOf('.')==-1?s.length():s.indexOf('.');
    if(len > extraRound + 3) {
        c = len - extraRound  - 3;
        s = s.substring(0, c) + "," + s.substring(c);
    }

    if(len > extraRound + 6) {
        c = len - extraRound  - 6;
        s = s.substring(0, c) + "," + s.substring(c);
    }

    if(len > extraRound + 9) {
        c = len - extraRound  - 9;
        s = s.substring(0, c) + "," + s.substring(c);
    }

    if(len > extraRound + 12) {
        c = len - extraRound  - 12;
        s = s.substring(0, c) + "," + s.substring(c);
    }

    if(negative) {
        s = '-' + s;
    }
    return s;
}

public static String addCommasNew(String s) {
    int extraRound = 0;
    boolean negative = false;
    int c;
    if(s.charAt(0) == '-') {
        negative = true;
        s = s.substring(1);
    }
    int len = s.indexOf(',')==-1?s.length():s.indexOf(',');
    if(len > extraRound + 3) {
        c = len - extraRound  - 3;
        s = s.substring(0, c) + "." + s.substring(c);
    }

    if(len > extraRound + 6) {
        c = len - extraRound  - 6;
        s = s.substring(0, c) + "." + s.substring(c);
    }

    if(len > extraRound + 9) {
        c = len - extraRound  - 9;
        s = s.substring(0, c) + "." + s.substring(c);
    }

    if(len > extraRound + 12) {
        c = len - extraRound  - 12;
        s = s.substring(0, c) + "." + s.substring(c);
    }

    if(negative) {
        s = '-' + s;
    }
    return s;
}

public static String removeScientific(String s) {
    int eIndex = s.indexOf('E');
    int initialPos = s.indexOf('.');
    String result = s;

    if (eIndex != -1){
        int base = Integer.parseInt(s.substring(eIndex+1));
        String pre = s.substring(0, initialPos);
        String pos = s.substring(initialPos+1, eIndex);
        String pos1 = ""; 
        if (base < pos.length()){
            String pos1a = pos.substring(0, base);
            String pos1b = pos.substring(base, pos.length());
            pos1 = pos1a + "." + pos1b; 
        } else {
            pos1 = pos.substring(0, pos.length());
            for (int i = 0; i < base-pos.length(); i++){
                pos1 = pos1 + "0";
            }
        } 
        result = pre + pos1;
    } 

    return result;
}

public static String changePointToComma(String s){
    int initialPos = s.indexOf('.');
    String result = s;
    if (initialPos != -1){
        result = s.substring(0, initialPos) + "," + s.substring(initialPos + 1, s.length());
    }

    return result;
}

public static String changeCommaToPoint(String s){
    int initialPos = s.indexOf(',');
    String result = s;
    if (initialPos != -1){
        result = s.substring(0, initialPos) + "." + s.substring(initialPos + 1, s.length());
    }

    return result;
}

public static String removeNumberFormat(String s){
    int initialPos = s.indexOf('.');
    String result = s;
    if (initialPos != -1){
        result = s.substring(0, initialPos) + s.substring(initialPos + 1, s.length());
        result = Formatter.removeNumberFormat(result);
    } else {
        return result = Formatter.changeCommaToPoint(s);
    }

    return result;
}

public static String roundDouble(String s, int presicion){
    int initialPos = s.indexOf('.');
    String result = s;
    String pre;
    String pos;

    if (initialPos != -1){
        pre = s.substring(0, initialPos);
        pos = s.substring(initialPos + 1, s.length());
        if (presicion < pos.length()){
            pos = s.substring(initialPos + 1, initialPos + 1 + presicion );
            int dec = Integer.parseInt(pos);
            int next = Integer.parseInt(s.substring(initialPos + 1 + presicion, initialPos + 2 + presicion )); //to round the las digit
            if (next > 4){
                dec = dec + 1;
                pos = dec + "";
                if ((dec+"").length() > presicion){
                    pre = (Integer.parseInt(pre) + 1) + "";
                    pos = "0";
                }
            }
        } else {
        }

        result = pre + "." + pos; 
    }

    return result;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文