• Franky

    (@liedekef)


    When entering “,” as decimal separator and “.” for thousands, and after that entering a balance for a financial account, the systems makes something totally different of it.
    A solution would be to not do this yourself, but let php help you. An example (simplified version from my plugin):

    
    function zero_decimal_currencies() {
       # returns an array of currencies that don't have decimals
       $currency_array = array (
        'BIF',
        'CLP',
        'DJF', 
        'GNF',
        'JPY',
        'KMF',
        'KRW',
        'MGA',
        'PYG',
        'RWF',
        'VND',
        'VUV',
        'XAF',
        'XOF',
        'XPF'
       );
       return $currency_array;
    }
    
       $locale = determine_locale();
       if (class_exists('NumberFormatter'))
               $localize_price=1; 
       else
               $localize_price=0;
    
       if ($localize_price)
               $formatter = new NumberFormatter( $locale."@currency=$cur", NumberFormatter::CURRENCY );
    
       $eme_zero_decimal_currencies_arr=zero_decimal_currencies();
       if (in_array($cur,$eme_zero_decimal_currencies_arr))
               $decimals = 0;
       else
               $decimals=2;  // make this an option
    
       if ($localize_price)
               $result = $formatter->formatCurrency($price, $cur);
       else
               $result = number_format_i18n($price,$decimals);
    

    This way you can keep a mathematical notation and just show a localized version based on currency ($cur) and the current locale.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Sultan Nasir Uddin

    (@manikmist09)

    Hi @liedekef

    Thank you for your suggestion. I will go through your suggested approach and, if possible, try to implement it.

    Thread Starter Franky

    (@liedekef)

    This is still a bug:
    – use “,” as decimal separator and “.” for thousands
    – create a bank account and set initial value ==> the value uses “.” for separator (and doesn’t allow anything else), so e.g. I enter “20.45”
    – check the bank account created: the balance marked is €204.500,00

    Fix currency error automatically adding 0000 (4 zeros) to the amount
    Hi WP Ever Admin
    First of all, thank you very much for your open source addon sharing.
    It’s amazing.
    But I would like to report a very annoying bug that messed up the currency calculation when I removed the two 00 after the “,” of the currency.
    Exp: Precision = 2 | and now set: Precision = 0
    Problem: When creating a new expense or income money voucher, I set the currency amount to : 100,000
    Then save
    Then the invoice will show the currency as 1,000,000,000 VND
    => It’s more than 4 zeros @@
    Please check again and fix this error. Thank you so much

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Currency issues’ is closed to new replies.