Page MenuHomePhabricator

Formatnum and expr gives erroneous calculation
Closed, DeclinedPublic

Description

Author: joanjoc

Description:
This error ocurrs in wikipedias using comma as a decimal separator according to the wiki's default locale, like in catalan wikipedia.

Tthe formatnum magicword almost follows the wiki locale, but the parser function #expr: use the dot as a decimal separator. This differences results in erroneous calculus in some templates. There's a set of examples at;

http://ca.wikipedia.org/wiki/Usuari:Joanjoc/formatnum


Version: unspecified
Severity: normal

Details

Reference
bz11156

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 9:47 PM
bzimport added a project: ParserFunctions.
bzimport set Reference to bz11156.
bzimport added a subscriber: Unknown Object (MLST).

webboy wrote:

You should use only English numbers without thousand separator (like 1000000.45) in #expr and formatnum without R.

To transform numbers from a local number ( like 1.000.000,45 ) to an English number without thousand separator, use {{formatnum: number |R}} (note the R):

{{formatnum: 1.000.000,45 |R}} => 1000000.45

Therefore, to multiply a local number with 10, and output a local number, you should use:

{{formatnum: {{#expr: {{formatnum: 5.199,75 | R }} * 10 }} }}

Output: 51.997,5