-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added informations in format_currency and format_number docs #3985
base: 3.x
Are you sure you want to change the base?
Added informations in format_currency and format_number docs #3985
Conversation
I added the format_number filter in this PR because it is really close to format_currency |
.. code-block:: twig | ||
|
||
{# €123.00 #} | ||
{{ 123 | format_currency('EUR', {lenient_parse:true}, 'en') }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be more descriptive of the lenient parsing effect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find a useful example, do you have any ideas ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure here, to be honest. As i see it, the "lenient_parse" is a way to allow data that is not perfectly in the expected syntax...
<?php
$formatter = NumberFormatter::create('fr-FR', NumberFormatter::CURRENCY);
foreach ([false, true] as $lenientParse) {
echo 'lenientParse: ' . ($lenientParse ? 'true' : 'false') . PHP_EOL;
$formatter->setAttribute(NumberFormatter::LENIENT_PARSE, $lenientParse);
echo $formatter->format(-9) . PHP_EOL;
echo $formatter->format('.9') . PHP_EOL;
echo $formatter->format(12.34000) . PHP_EOL;
echo $formatter->format($formatter->parse('56,7800000')) . PHP_EOL;
echo $formatter->format($formatter->parse('56,78')) . PHP_EOL;
echo $formatter->format($formatter->parse('56,78€')) . PHP_EOL;
echo $formatter->format($formatter->parse('56,78 €')) . PHP_EOL;
echo $formatter->format($formatter->parse('56,78 €')) . PHP_EOL;
}
Would render
lenientParse: false
-9,00 €
0,90 €
12,34 €
-0,00 €
-0,00 €
-0,00 €
-0,00 €
56,78 €
lenientParse: true
-9,00 €
0,90 €
12,34 €
+56,78 €
+56,78 €
+56,78 €
+56,78 €
56,78 €
As you see, it's when the parse
method is called it makes a difference.
But it this specific case (currency), as we do not call "parse
", and the format
method only accept int|float
, i don't see a concrete exemple where it would have an impact.
No description provided.