Torann / laravel-currency

This provides Laravel with currency functions such as currency formatting and conversion using up-to-date exchange rates.
http://lyften.com/projects/laravel-currency
BSD 2-Clause "Simplified" License
390 stars 138 forks source link

Currency formatting issue #133

Open easyitis opened 4 years ago

easyitis commented 4 years ago

Using version 1.0.17. Some currencies are not getting formatted correctly. Example: currency(1,'USD','AED',true) => "دإ‏ 3,6731" (expected "دإ‏ 3.67")

easyitis commented 4 years ago

On debugging it can be seen that this is where the issue is:

        // Match decimal and thousand separators
        preg_match_all('/[\s\',.!]/', $format, $separators);

        // NOTE: $separators is calculated as [" ", ",", "."]

        if ($thousand = Arr::get($separators, '0.0', null)) {
            if ($thousand == '!') {
                $thousand = '';
            }
        }

        $decimal = Arr::get($separators, '0.1', null);

This issue occurs whenever there's a space in the format code, for example: AED: دإ‏ 1,0.00 ARS: $ 1,0.00

As an interim solution we can remove the spaces from all the format codes.

AEK-BKF commented 3 years ago

Same issue with me, for SAR also

easyitis commented 3 years ago

Same issue with me, for SAR also

Please try removing spaces from all the format codes.

zpoll92 commented 3 years ago

Same issue here. Very annoying. If I remove the space then it doesn't look correct. @Torann can you please fix this ASAP?

wrabit commented 3 years ago

"fix this ASAP" for an open source package doesn't always go down well. If you see how you can fix it, consider a PR. But it's unfortunate and concerning to see there doesn't seem to be much activity on this project anymore. Maybe the maintainer can consider opening up sponsorship to motivate more work on it.

Torann commented 3 years ago

Unfortunately I don't have time to look into this, but I will be more than happy to review a PR.