Module talk:ConvertNumeric

numeral_to_english
Converts a given integer to its English text representation. Accepts integers (including negative and zero), decimal numbers, and scientific notation. Any value not matching these is evaluated as an expression and the result is used. Any value with magnitude less than 1000 quadragintillion (10126) is supported, as well as some larger numbers such as one centillion (10303) and one millinillion (103003).

Optional parameters

 * numerator
 * denominator: both necessary for fractions
 * case: Set to "U" or "u" to capitalize result
 * sp: Set to "us" to remove "and" between hundreds and tens places
 * adj: Hyphenate
 * ord: Ordinal (e.g. first instead of one)
 * pl: Plural
 * lk: If set to 'on', will link the words "billion" and larger to their respective short-scale article sections. This might be helpful for disambiguation. Subsets of words can be linked to by specifying them, e.g. lk=trillion will link only "trillion", and lk=trillion,quadrillion will link only those two.
 * negative: Sets the word to use for negative if the supplied value is negative (e.g. negative or minus)
 * round: If set to 'on', will round the number to the nearest one- or two-word integer. |round=down and |round=up are similar but round down and up respectively.

decToHex
This takes a string and converts all the decimal sequences in it to hex.

produces

roman_to_numeral
Hi, I wanted to use this function in a module I'm working on (Module:Sandbox/Bility/SortName), but it doesn't appear to be exposed publicly. Is that right, or could I just not figure out how to access it using ? For now I've copy/pasted it into my module. — Bility (talk) 22:23, 11 April 2013 (UTC)

Make more functions public
Would be good if the functions for  and   be made public (maybe the others as well), as currently to access them from another module I need to do this abomination -   (just to get the   value included; can ignore the last 6 in my personal example, but maybe not in other uses), which I get by using the public method   It also does a lot of other unnecessary code that is not relevant for my specific needs of converting a number into English. --Gonnym (talk) 14:05, 21 September 2018 (UTC)
 * OK but for completeness you might indicate where this would be used and briefly why it is not integrated into this module. Johnuniq (talk) 01:33, 22 September 2018 (UTC)
 * Sorry, did not have this on my watchlist and didn't see you responded. For my specific use-case (Module:Television episode short description), I need to get a number converted to an ordinal word in English. I call this function from another module as this is just the conversion part of the code, not the actual work the module does. For me the only thing I really need is a direct access to  (to be more specific to the 100, as I'll never need a number bigger than 100, but I can live with that few extra code lines) and to pass it only 2 variables - a number and true for ordinal. So a public function of   that takes a number would be exactly what I need (and it can then pass to   the rest of the values it needs). Another issue that I have with the current flow, is that I cannot send the number as a number, but as a text, as it fails at  . Hope I answered your questions. --Gonnym (talk) 10:16, 3 November 2018 (UTC)
 * @Gonnym: I am happy to fix this and I agree the interface is too complex and fragile. I think  should continue to work as it does now so nothing breaks, but should also accept   where   is a table. For example,   could be used. However, I don't want to take the time to decode what Module:Television episode short description is doing and I haven't looked at Module:ConvertNumeric for a very long time so have forgotten why access to functions like numeral_to_english_less_1000 might be helpful. A very quick look makes me think your module needs things like translating 1 to 1st and 12 to twelfth. Would passing a table as just described do all you need? Why does your module have getOrdinalIndicatorLessThan1000 and related logic? I would have thought that spell_number should do all that is needed. Johnuniq (talk) 22:47, 3 November 2018 (UTC)
 * , I was actually thinking of bypassing that whole section, and adding to local p = {} a new function numeral_to_english_ordinal_less_1000 which will be something like this:

The code above could use your idea for the options table if ordinal can be used along with another param (haven't checked to see). Regarding my uses, you are correct. I use this module to convert a number to to an ordinal in the style of "twelfth". I have the additional logic in my code since as far as I can tell, this module does not convert a number to the style I needed. --Gonnym (talk) 06:44, 4 November 2018 (UTC)
 * @Gonnym: I'm wondering why you are thinking of that function. Any change to this module should only occur after working out if something is missing. Please give an example of input and output showing results from your code and this module to show the style issue. Are you saying this module cannot turn '12' into 'twelfth'? Johnuniq (talk) 07:05, 4 November 2018 (UTC)
 * That isn't what I said. I said that I use this module to convert 12 to twelfth, but 1 to 1st, as far as I can tell, it doesn't. --Gonnym (talk) 07:07, 4 November 2018 (UTC)
 * OK, so the problem is that you need "1st" but the module only generates "first". I'll think about that and will ping you in a couple of days. Johnuniq (talk) 08:38, 4 November 2018 (UTC)
 * Well, technically, I don't need anything anymore as I've got everything sorted, but if this module did have this, it might be useful to others. But that really wasn't my point I was trying to make. I believe that the current entry point function is flawed from a coding perspective. The main function is around 100 lines long and does so many things that its a nightmare for readability and maintenance (and as I pointed out, if I pass a number which is a number, it fails). Some of the parameters are also mutually exclusive (such as plural and ordinal) so having them both as arguments in the same function doesn't serve anything. Instead, I would argue that having several entry points based on those mutually exclusive parameters would be a better design approach and would both allow for better readability, maintenance and future expansions (such as this). --Gonnym (talk) 11:14, 4 November 2018 (UTC)

Feature request
It would be nice if  (or an equivalent function) could do a combination of numerals and words. For example, 15×1012 would be rendered as "15 trillion". Take this a step further with decimal places: 15.1 trillion. Thanks. — howcheng  {chat} 00:24, 7 November 2018 (UTC)
 * Is there an example of an article where it would be helpful to use a template to turn "×1012" into "trillion"? I would find it easier to type the latter. Johnuniq (talk) 02:48, 7 November 2018 (UTC)
 * Sorry, I didn't mean literally "15×1012", but "15000000000000". And I'm mostly thinking of a number that large that comes as a result of a calculation. For example, in the introduction of 2016 Indian banknote demonetisation, we have The banknotes that were not deposited were only worth ₹10,720 crore (102.7 billion). The Western equivalent was not there until yesterday, and I made the template crore to do the conversion, which ends up as . I can then wrap with number to word, but it comes out as "", when "102.7 billion" is easier to understand. — howcheng  {chat} 16:53, 7 November 2018 (UTC)
 * I've added that to a to do list but I've got occupied elsewhere and am not likely to do anything for quite a while. I'll ping you if there is good news. If implemented, I suppose it should be called with a dedicated template that produces thousand/million/billion/trillion rather than adding yet another option to number to word. Johnuniq (talk) 00:19, 8 November 2018 (UTC)
 * Fair enough. If I knew Lua syntax, I'd be happy to do it myself. — howcheng  {chat} 17:19, 8 November 2018 (UTC)

US parameter of Template:Number to word
Is the us parameter of number to word working correctly? The output does not seem to say "nine hundred and ninety-nine thousand" (per this) either with the parameter or without:





Thanks, It Is Me Here (talk) 11:05, 10 April 2020 (UTC)


 * I'm seeing "and" without the parameter, as the doc says it should work. --Gonnym (talk) 11:10, 10 April 2020 (UTC)


 * Thanks for the reply. For me, the output text reads "nine hundred ninety-nine billion nine hundred ninety-nine million nine hundred ninety-nine thousand nine hundred and ninety-nine" in both cases. Are you saying that you see "nine hundred and ninety-nine billion"? It Is Me Here (talk) 13:08, 10 April 2020 (UTC)
 * Unless there is a specific issue with a very long number, use short examples as it's easier to read. Here I see "and" in the first and no "and" in the second.
 * --Gonnym (talk) 13:51, 10 April 2020 (UTC)
 * --Gonnym (talk) 13:51, 10 April 2020 (UTC)
 * --Gonnym (talk) 13:51, 10 April 2020 (UTC)


 * Okay, this is a shorter example. My question is whether you see an "and" in the number of thousands. I agree I also see an "and" in the number of units. It Is Me Here (talk) 15:37, 10 April 2020 (UTC)
 * Ok, I now understand what you are asking. I do not see. Should it though? Number to word links to English numerals which gives an example of 999 - nine hundred and ninety-nine thousand (inclusively British English, Irish English, Australian English, and New Zealand English) / nine hundred ninety-nine thousand (American English) - notice that the American English example does not have "and". Since I'm not a linguistic or familiar with this topic, this is the most I can help you. --Gonnym (talk) 15:44, 10 April 2020 (UTC)
 * Another angle would be to ask whether it matters. Those of us who wrote enormous programs to generate lists of roman numerals as a training exercise would care, but is there any use-case at Wikipedia where the examples matter? Johnuniq (talk) 00:00, 11 April 2020 (UTC)

Template-protected edit request on 25 March 2021
Copy changes from sandbox. This will make it possible to access all of the normalization features in modules that was previously only available to templates. For example,  will return "ninety-nine" whereas   will crash. User:GKFXtalk 18:17, 25 March 2021 (UTC)
 * The module is a bit of a mess that I have been intending to clean for a couple of years. That change looks good but I have some questions since I'd prefer to avoid adding more incompatability.
 * I'm too lazy to test your above statement. Are you saying that if a module calls this module with  then a crash occurs? If so, that should be fixed.
 * What does this comment mean?
 * What is "_full" in ? I can see that it takes a table as the parameter, but no other function has a convention where "_full" is used for that.
 * Johnuniq (talk) 04:29, 26 March 2021 (UTC)
 * Ah right I see. It looks like a nice module to me anyway! In order of your questions: yes it does crash because all the string cleanup is in (what I had called)  rather than  . It would arguably be fine to just move that to  . As for the word "full" it means that the function is a complete replacement for   rather than a fragile one which can't handle whitespace.
 * I have made another edit to the sandbox which makes spell_number and spell_number2 handle whitespace directly so  and   are now fine, rather than adding a new function. User:GKFXtalk 11:31, 26 March 2021 (UTC)
 * Thanks, that's greatly improved the code and has motivated me to look at my old notes to see what else should be done. I did a minor edit to the sandbox but plan to investigate a couple of other issues before this goes live. I'll also want to remind myself how testing is done. Johnuniq (talk) 04:29, 27 March 2021 (UTC)
 * BTW I'm hoping you will check my edits. In particular diff. Am I missing something or have those three regexes always had a redundant (wrong) component? Johnuniq (talk) 09:14, 27 March 2021 (UTC)
 * Yes I would agree that 12.3-E4 is not a legitimate way to write exponentials and that your edits are fine. User:GKFXtalk 13:21, 27 March 2021 (UTC)