Module talk:Formatnum
![]() | This module was considered for deletion on 2018 September 21. The result of the discussion was "keep". |
language:formatNum(tonumber(number),…)
If I read the code correctly, then tonumber(number)
is already computed and stored in the variable named “value”. Incnis Mrsi (talk) 09:55, 22 October 2019 (UTC)
- @Incnis Mrsi: It's true that the variable value stores the numeric value of the parameter passed as number. However, if you read line 44, the
mw.language:formatNum()
call doesn't handle exponents properly. The lines 41 to 52 convert number to a string, then if there is an exponent, it stores the significand as a string back into number and the exponent in exponent. So by the time the code reaches lines 84 or 86 the string value in 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 usemw.language:formatNum()
. Writinglanguage:formatNum(value, ...)
wouldn't work properly if the number passed contained an exponent. Hope that makes sense. --RexxS (talk) 16:18, 22 October 2019 (UTC)- Ah, got it – the variable may be reassigned with
number = string.sub(number, 1, pos - 1)
. Incnis Mrsi (talk) 17:11, 22 October 2019 (UTC)
- Ah, got it – the variable may be reassigned with
Zero precision not working
If I use fn.formatNum(5435.12345,"en",2)
I get the result 5,435.12
as expected. Similarly with other positive values for precision. But with fn.formatNum(5435.12345,"en",0)
the number is returned with all the post decimal point digits, i.e. 5,435.12345
). Looking at the code there are a couple of if prec > 0 then ... elseif prec < 0 then .. end
blocks which suggests zero is ignored. Is this intentional or an oversight? Jts1882 | talk 15:35, 9 December 2019 (UTC)
#invoke
![]() | It is requested that an edit be made to the template-protected module at Module:Formatnum. (edit · history · last · links · sandbox · edit sandbox · sandbox history · sandbox last edit · sandbox diff · test cases · transclusion count · protection log) This template must be followed by a complete and specific description of the request, so that an editor unfamiliar with the subject matter could complete the requested edit immediately.
Edit requests to template-protected pages should only be used for edits that are either uncontroversial or supported by consensus. If the proposed edit might be controversial, discuss it on the protected page's talk page before using this template. Consider making changes first to the module's sandbox and test them thoroughly here before submitting an edit request. To request that a page be protected or unprotected, make a protection request. When the request has been completed or denied, please add the |
The production code cannot be #invoke'd normally, only wrapped by templates. The sandbox code fixes this. Trigenibinion (talk) 11:56, 3 March 2021 (UTC)
Not done for now: please establish a consensus for this alteration before using the
{{edit template-protected}}
template. It is not obvious to me that it would be beneficial to allow a module-version to be used. What is the proposed use case where it is necessary? (See also Template talk:Infobox for a related case.) Izno (talk) 02:11, 5 June 2021 (UTC)- This is needed so that this module or another one can be conditionally #invoke'd. See Template:FXConvert/sandbox. Trigenibinion (talk) 08:43, 17 July 2022 (UTC)