Java 如何使用数字格式类设置货币格式

Java 如何使用数字格式类设置货币格式,java,android,Java,Android,我是Android开发的新手,我被困在一个地方。我想格式化我的货币,我设置为显示不带小数点和逗号 示例:现在它显示为23000.00。但是我想要像23000这样的货币;我该怎么做 我尝试了格式化程序类,但这对我没有帮助 现在就是这样设置的 public class CurrencyFormatter { public static String setsymbol(BigDecimal data, String currency_symbol) { Number

我是Android开发的新手,我被困在一个地方。我想格式化我的货币,我设置为显示不带小数点和逗号

示例:现在它显示为
23000.00
。但是我想要像23000这样的货币;我该怎么做

我尝试了格式化程序类,但这对我没有帮助

现在就是这样设置的

public class CurrencyFormatter {

    public static String setsymbol(BigDecimal data, String currency_symbol)
    {
        NumberFormat format = NumberFormat.getCurrencyInstance(Locale.ENGLISH);
        format.setCurrency(Currency.getInstance(currency_symbol));
        String result=data+" "+" دينار";
        return result;
    }
}
我希望输出是(阿拉伯语文本)23000,而不是(阿拉伯语测试)23000.00

 NumberFormat format = NumberFormat.getCurrencyInstance(Locale.getDefault());
 format.setCurrency(Currency.getInstance("USA"));
 String result = format.format(1234567.89);
这是美国的格式集,您可以使用国家代码进行更改


参考

基本上,您需要一个货币格式化程序对象

NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(currentLocale);
之后,您可以设置金额:

Double currencyAmount = new Double(23000.00);
String formattedOutput = currencyFormatter.format(currencyAmount);

Oracle参考文档中提供了更多选项和解释:

试试这个,它将以这种格式显示23000个不带小数点的数字,它将在数字中显示千位分隔符

String result = null;
    try {
        // The comma in the format specifier does the trick
        result = String.format("%,d", Long.parseLong(data)); // use this result variable where you want to use.

        result = result + " " + " دينار";  // to append arabic text, do as you were doing before.

    } catch (NumberFormatException e) {
    }

货币不是静态的,它可以是任何数字。不,它不是。查看问题中的字符串结果。我必须使用阿拉伯文字,后面跟着货币,这是动态的。因此,请相应地帮助。阿拉伯文字将被追加,就像你以前做的一样。请检查我的更新答案。可能是这样的,result=“دينا㶈撴”+“”+result;在你的答案中,Long.parseLong(数据)中“data”的引用是什么。因为当我把数据放在括号中时,它显示错误。那里的数据是什么?请解释一下。@AreebKhan data是你的变量,它在你的代码中作为参数出现在你的函数中。