Skip to content
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

Open
wants to merge 6 commits into
base: 3.x
Choose a base branch
from

Conversation

FlorianChenot
Copy link

No description provided.

doc/filters/format_currency.rst Outdated Show resolved Hide resolved
doc/filters/format_currency.rst Outdated Show resolved Hide resolved
doc/filters/format_currency.rst Outdated Show resolved Hide resolved
doc/filters/format_currency.rst Outdated Show resolved Hide resolved
doc/filters/format_currency.rst Outdated Show resolved Hide resolved
doc/filters/format_currency.rst Outdated Show resolved Hide resolved
@FlorianChenot
Copy link
Author

I added the format_number filter in this PR because it is really close to format_currency

@FlorianChenot FlorianChenot changed the title add informations in format_currency doc add informations in format_currency and format_number doc Jan 26, 2024
@FlorianChenot FlorianChenot changed the title add informations in format_currency and format_number doc add informations in format_currency and format_number docs Jan 26, 2024
@FlorianChenot FlorianChenot changed the title add informations in format_currency and format_number docs Added informations in format_currency and format_number docs Jan 26, 2024
.. code-block:: twig

{# €123.00 #}
{{ 123 | format_currency('EUR', {lenient_parse:true}, 'en') }}
Copy link
Contributor

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

Copy link
Author

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 ?

Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants