簡體   English   中英

Java 中的丹麥語 (DKK) 貨幣格式

[英]Denish (DKK ) Currency Formatting in Java

在 Java/Android 中,我如何有效地將 10.00 等浮點數轉換為 10,00 作為丹麥貨幣。 我可以根據需要轉換 1000,但不能轉換為 10 或 10.00

處理貨幣的一個好方法是使用BigDecimal 這是我最近編寫的一些代碼的示例(我只是將貨幣更改為 DNK):

public static Currency DEFAULT_CURRENCY = Currency.getInstance("DNK");
public static RoundingMode DEFAULT_ROUNDING_MODE = RoundingMode.CEILING;
public static int DEFAULT_SCALE = DEFAULT_CURRENCY.getDefaultFractionDigits();

    /**
     * Convert the value in a BigDecimal having scale and rounding mode aligned to the currency settings
     * @param value
     * @return BigDecimal with the custom scale and settings
     */
    public static BigDecimal setCustomScale(int value) {
        return new BigDecimal(value).setScale(DEFAULT_SCALE, DEFAULT_ROUNDING_MODE);
    }

這里還有一些適用於 Android 的 BigDecimal 示例。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM