I thought I was going crazy before I went out of my way to restore PHP 7.4.13 to try it to make sure. It has changed in PHP 8.x!
Code:
$a = new \NumberFormatter('en_US', \NumberFormatter::CURRENCY);
$a->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, 8);
$a->setSymbol(NumberFormatter::CURRENCY_SYMBOL, ''); // It's empty because I want it "minimal" for a table.
var_dump($a->formatCurrency(0.0043, 'BTC'));
Output in PHP 7.4.13:
string(6) "0.0043"
Output in PHP 8.0.1:
string(11) "BTC 0.0043"
Conclusion:
Something has changed.
Question:
How to make PHP 8.0.1 behave like it used to?
Clarification:
That is, to make the money sum outputted in a "minimal" manner, with just the number.
Prediction 1:
Somebody might respond something like: "Just output the number manually for these cases!"
To this, I respond: It has to be the number formatter in currency mode. There are wild differences between locales/languages in how money sums are to be formatted. I need to use this and tell it to forgo the symbol.
Prediction 2:
Somebody might respond something like: "Just str_replace/preg_replace out the symbol! Easy!"
To this, I respond: Not all locales/languages use the same format. It's a whole science of numerous different formats, impossible to account for with a simple string replacement.
I want to do this right, which is what I thought I had. Until just now, when PHP 8 has decided to change this around. I'm not sure if it's a bug or what.
Research:
I cannot find any mention whatsoever of PHP 8 here: https://www.php.net/manual/en/numberformatter.formatcurrency.php
string(11) "BTC 0.0043"
– user14756437 Jan 8 at 21:58