Fixed How to remove decimals in currency format

katoona

Member
Affected version
2.1.9
I want to show price without decimals, and the moneyformat has been deprecated in PHP7.4.

Does anybody have a bit of quick advice on what I can add in this field to make $1,234.50 --> $1,234 (no decimals)

money-format.jpg

Or, where I can alter the code manually in the files...
 
Last edited:
This is actually a bug because we don't actually support money_format formatting. You can only control the position of the {symbol} and the {value} and they are the only two tokens we support (though admittedly there aren't really many other permutations left).

We'd probably be looking to clarify what format "Other" expects.

To answer your question, the currency format defined in the language isn't actually what should control the decimals or precision. In fact the rules of each specific currency are what control that.

Many currencies do display currencies to two decimal places but only a handful of currencies worldwide don't actually have that concept.

For example if you wanted to display a value in "Japanese yen" then it would look like this ¥1000 because that currency has no real concept of fractional units.

So, all that being said, there's currently no support for doing what you want, but we will clarify the meaning of this "Other" field going forward.
 
I mean if it was significant enough for you to want to modify it either with a direct code edit or an add-on then you would extend/edit the XF\Data\Currency class and extend/modify the getCurrencyData method.

PHP:
'USD' => ['code' => 'USD', 'symbol' => '$',    'precision' => 2, 'phrase' => 'currency.usd', 'fa' => 'fa-dollar-sign'],

Would become:
PHP:
'USD' => ['code' => 'USD', 'symbol' => '$',    'precision' => 0, 'phrase' => 'currency.usd', 'fa' => 'fa-dollar-sign'],

Though note that a value of 1234.50 would become 1235 in that case due to rounding.
 
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.1.10).

Change log:
Make the appropriate usage of a language's currency_format value more clear.
There may be a delay before changes are rolled out to the XenForo Community.
 
I mean if it was significant enough for you to want to modify it either with a direct code edit or an add-on then you would extend/edit the XF\Data\Currency class and extend/modify the getCurrencyData method.

PHP:
'USD' => ['code' => 'USD', 'symbol' => '$',    'precision' => 2, 'phrase' => 'currency.usd', 'fa' => 'fa-dollar-sign'],

Would become:
PHP:
'USD' => ['code' => 'USD', 'symbol' => '$',    'precision' => 0, 'phrase' => 'currency.usd', 'fa' => 'fa-dollar-sign'],

Though note that a value of 1234.50 would become 1235 in that case due to rounding.
Hi @Chris D !

Where is this "XF/Data/Currency exacly? I did not find a setting like that and I wasnt able to find it in ftp either.. (or file).

Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.1.10).

Change log:

There may be a delay before changes are rolled out to the XenForo Community.
What do you mean?
I still have this issue, I want to get rid of the .00 part, to get full numbers, but there's no option like this in XF.
 
Last edited:
I mean if it was significant enough for you to want to modify it either with a direct code edit or an add-on then you would extend/edit the XF\Data\Currency class and extend/modify the getCurrencyData method.

PHP:
'USD' => ['code' => 'USD', 'symbol' => '$',    'precision' => 2, 'phrase' => 'currency.usd', 'fa' => 'fa-dollar-sign'],

Would become:
PHP:
'USD' => ['code' => 'USD', 'symbol' => '$',    'precision' => 0, 'phrase' => 'currency.usd', 'fa' => 'fa-dollar-sign'],

Though note that a value of 1234.50 would become 1235 in that case due to rounding.

I tried editing: src/XF/Data/Currency.php
but still shows decimal @

@NandorHUN @Kruzya

 
Back
Top Bottom