java - 如何使用数字格式类格式化货币

标签 java android

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

示例:现在显示为 23000.00。但我想要23,000这样的货币;我该怎么做?

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

现在就是这样设置的。

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;
    }
}

我预计输出为(阿拉伯文文本)23,000 而不是(阿拉伯文测试)23000.00

最佳答案

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

NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(currentLocale);

之后您可以格式化金额:

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

Oracle 的引用文档中提供了更多选项和说明:https://docs.oracle.com/javase/tutorial/i18n/format/numberFormat.html

关于java - 如何使用数字格式类格式化货币,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56625300/

相关文章:

java - 连接多个表不返回结果

android - 无法解析 : com. android.support :support-v4:26. 3.1

android - 如何截断 Realm android中的所有表

android - 如何知道android :id Android expects?是什么

java - 将base64中的图像从rest服务返回到img src标签

java - 将字符串中的字符增加特定值

Javassist:如何创建代理的代理?

java - 如何为 Spring 的 @PropertySource 注解传递命令行参数?

android - webview 加载包含 .js 的本地 html 文件作为 <script src>

android - 应用程序关闭时从 BLE 设备向手机推送通知或 Intent