Last modified: 2009-01-13 11:25:50 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T14560, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 12560 - formatnum formats template parameters instead of the returning result
formatnum formats template parameters instead of the returning result
Status: RESOLVED WORKSFORME
Product: MediaWiki extensions
Classification: Unclassified
ParserFunctions (Other open bugs)
unspecified
All All
: Normal normal (vote)
: ---
Assigned To: Nobody - You can work on this!
http://de.wikipedia.org/w/index.php?t...
: testme
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2008-01-09 09:03 UTC by WIKImaniac
Modified: 2009-01-13 11:25 UTC (History)
2 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description WIKImaniac 2008-01-09 09:03:19 UTC
According to the wiki's default locale settings in de.wikipedia.org the magic word "formatnum" leads to replacing "." by ",", e.g. {{formatnum:1.2}} results in "1,2".

If a template with some parameters is called and the result of this template should be formatted via "formatnum" a parser error occurs. This happends because the parameters contain "," and the parser expects to receive ".".

example:

{{formatnum: {{sum|1.2|3.4}} }}

1. step of incorrect evalutation:

{{sum|1,2|3,4}}

2. step of incorrect evaluation: (parser error in Template:Sum)

{{#expr: 1,2 + 3,4}}


workaround:

{{formatnum: {{#expr: 1,2 + 3,4}} }}
Comment 1 WIKImaniac 2008-01-09 09:32:31 UTC
correction of workaround:

{{formatnum: {{#expr: 1.2 + 3.4}} }}
Comment 2 Brion Vibber 2008-01-11 20:10:32 UTC
I'm afraid there's not much to do about this other than ensure that you're using proper formatting for your math.

The system shouldn't try to guess whether input is locale-formatted or not, since there are many many ambiguous cases... does "5.000" mean five thousand or five to three decimal places? There's no way to know in isolation.
Comment 3 WIKImaniac 2008-01-11 23:39:53 UTC
Hi Brion, you missunderstood the description of the problem. The problem is the order of evaluation. The parser should evaluate "formatnum(sum(1.2, 3.4))" if I'm writing {{formatnum: {{sum|1.2|3.4}} }}. But actually the expression is evaluated in follwing order: "sum(formatnum(1.2), formatnum(3.4))" which leads to the expression "sum(1,3, 3,4)" and ends in a parser error. Of course the parser shouldn't "guess" the format of the parameters. But it should evaluate the expressions in the correct order.
Comment 4 Brion Vibber 2008-01-12 00:53:26 UTC
Can you provide the text of this Template:Sum used in your examples? It doesn't seem to be present on de.wikipedia.org.
Comment 5 WIKImaniac 2008-01-12 09:09:53 UTC
The Template:Sum is a fictive example and would have been coded like this:

{{#expr: {{{1|0}}} + {{{2|0}}} }}

The described problem actually occured in the template "Vorlage:Klimatabelle" and its sub-template "Vorlage:Klimatabelle/Durchschnitt" which calculates the average of twelve values.

The workaround can be found here:
http://de.wikipedia.org/w/index.php?title=Vorlage%3AKlimatabelle&diff=40952394&oldid=40951597
Comment 6 Brion Vibber 2008-01-14 23:12:29 UTC
I'm still unable to reproduce any problem with the examples.

Vorlage:Sum:
{{#expr: {{{1|0}}} + {{{2|0}}} }}

Vorlage:Sumwrapper:
{{formatnum: {{sum|{{{1}}}|{{{2}}}}} }}

Invocation:
{{sumwrapper|1.2|3.4}}

Tested both with old and new parser.
Comment 7 WIKImaniac 2008-01-15 08:32:05 UTC
The problem occurs with this code:

Vorlage:Klimatabelle:

{{formatnum: {{Klimatabelle/Durchschnitt{{!}} {{{hmjan|0}}} {{!}} {{{hmfeb|0}}} {{!}} {{{hmmär|0}}} {{!}} {{{hmapr|0}}} {{!}} {{{hmmai|0}}} {{!}} {{{hmjun|0}}} {{!}} {{{hmjul|0}}} {{!}} {{{hmaug|0}}} {{!}} {{{hmsep|0}}} {{!}} {{{hmokt|0}}} {{!}} {{{hmnov|0}}} {{!}} {{{hmdez|0}}} }} }}

While Vorlage:Klimatabelle/Durchschnitt contains following code:

{{#expr: ({{{1|0}}} + {{{2|0}}} + {{{3|0}}} + {{{4|0}}} + {{{5|0}}} + {{{6|0}}} + {{{7|0}}} + {{{8|0}}} + {{{9|0}}} + {{{10|0}}} + {{{11|0}}} + {{{12|0}}}) / 12 round 1 }}

The parser error doesn't occur if I change the code of Vorlage:Klimatabelle to:

{{formatnum: {{#expr: ({{{hmjan|0}}} + {{{hmfeb|0}}} + {{{hmmär|0}}} + {{{hmapr|0}}} + {{{hmmai|0}}} + {{{hmjun|0}}} + {{{hmjul|0}}} + {{{hmaug|0}}} + {{{hmsep|0}}} + {{{hmokt|0}}} + {{{hmnov|0}}} + {{{hmdez|0}}}) / 12 round 1 }} }}
Comment 8 Brion Vibber 2008-01-16 03:49:11 UTC
Ok, sample usage:

{{Klimatabelle|hmjan=11|hmfeb=12|hmmär=13|hmapr=14|hmmai=15|hmjun=16|hmjul=17|hmaug=18|hmsep=19|hmokt=20|hmnov=21|hmdez=22}}


I still can't reproduce any problem with the formatting, either with old or new parser, except this:

With the new parser (not yet live), your {{!}} usages are incorrect and the entire template fails. Use | only here.


I get 16.5 in English or 16,5 set to German.
Comment 9 Jelte (WebBoy) 2008-08-11 20:44:04 UTC
Accidentally marked as WORKSFORME.
Comment 10 Happy-melon 2009-01-13 11:25:50 UTC
But it *does* WORKFORME... :-D

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links