Content deleted Content added
Incnis Mrsi (talk | contribs) |
Zero precision not working? |
||
Line 7:
: {{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)
:: Ah, got it{{snd}}the variable may be reassigned with <code>number = string.sub(number, 1, pos - 1)</code>. [[User:Incnis Mrsi|Incnis Mrsi]] ([[User talk:Incnis Mrsi|talk]]) 17:11, 22 October 2019 (UTC)
==Zero precision not working==
If I use <code>fn.formatNum(5435.12345,"en",2)</code> I get the result <code>5,435.12</code> as expected. Similarly with other positive values for precision. But with <code>fn.formatNum(5435.12345,"en",0)</code> the number is returned with all the post decimal point digits, i.e. <code>5,435.12345</code>). Looking at the code there are a couple of <code>if prec > 0 then ... elseif prec < 0 then .. end</code> blocks which suggests zero is ignored. Is this intentional or an oversight? <span style="font-family:Arial;background:#d6ffe6;border:solid 1px;border-radius:5px;box-shadow:darkcyan 0px 1px 1px;"> [[User:Jts1882|Jts1882]] |[[User talk:Jts1882| talk]] </span> 15:35, 9 December 2019 (UTC)
|