2017-01-16 44 views
-2

在Java/Android中,我怎樣纔能有效地將浮動幣從10.00兌換成10,00作爲拒絕貨幣。 我是ablle可根據需要轉換1000,但不能轉換爲10或10.00在丹麥的丹麥貨幣格式化(DKK)

+2

發佈一些代碼你試過的一直到現在 –

+0

NumberFormat format = NumberFormat.getCurrencyInstance (Locale.getDefault()); format.setCurrency(Currency.getInstance(「DKK」)); format.format(amount); – param

+0

我可否知道爲什麼要投票? ,我嘗試過不同的方式,但我沒有得到預期的輸出。 – param

回答

0

處理貨幣的好方法是使用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); 
    } 

Here也爲Android BigDecimal的一些例子。