Module talk:Formatnum: Difference between revisions

Content deleted Content added
language:formatNum(tonumber(number),…): it wouldn't work properly if the number passed contained an exponent
Line 4:
 
If {{serif|I}} read the code correctly, then <code>tonumber(number)</code> is already computed and stored in the variable named “value”. [[User:Incnis Mrsi|Incnis Mrsi]] ([[User talk:Incnis Mrsi|talk]]) 09:55, 22 October 2019 (UTC)
:
: {{re|Incnis Mrsi}} It's true that the variable {{var|value}} stores the numeric value of the parameter passed as {{var|number}}. However, if you read line 44, the <code>mw.language:FormatNum()</code> call doesn't handle exponents properly. The lines 41 to 52 convert {{var|number}} to a string, then if there is an exponent, it stores the [[significand]] as a string back into {{var|number}} and the exponent in {{var|exponent}}. So by the time the code reaches lines 84 or 86 the string value in {{var|number}} may or may not be the same as that passed into the function. So it's necessary to again convert that string back to a number in order to use <code>mw.language:FormatNum()</code>. Writing <code>language:formatNum(value, ...)</code> wouldn't work properly if the number passed contained an exponent. Hope that makes sense. --[[User:RexxS|RexxS]] ([[User talk:RexxS|talk]]) 16:18, 22 October 2019 (UTC)