Jump to content

Module talk:ConvertNumeric

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Gonnym (talk | contribs) at 10:43, 3 November 2018 (Make more functions public: more info). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

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).

Examples

  • {{#invoke:ConvertNumeric | numeral_to_english | -123456789.25 }}
    negative one hundred twenty-three million four hundred fifty-six thousand seven hundred and eighty-nine point two five
  • {{#invoke:ConvertNumeric | numeral_to_english | 5E30 | case=u | ord=on | lk=on }}
    Five nonillionth
  • {{#invoke:ConvertNumeric | numeral_to_english | 57000 | round=on | plural=on}}
    sixty thousands
  • {{#invoke:ConvertNumeric | numeral_to_english | 35 + 42 | adj=on }}
    seventy-seven
  • {{#invoke:ConvertNumeric | numeral_to_english | 3+1/2 }}
    three point five
  • {{#invoke:ConvertNumeric | numeral_to_english | 3 | numerator = 1 | denominator = 2 }}
    three and a half

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.

{{#invoke:ConvertNumeric|decToHex|10 20 40 1024 78912345|minlength=4}}

produces

000A 0014 0028 0400 4B41B59

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 require ('Module:ConvertNumeric')? For now I've copy/pasted it into my module. — Bility (talk) 22:23, 11 April 2013 (UTC)[reply]

Make more functions public

Would be good if the functions for numeral_to_english_less_1000 and numeral_to_english_less_100 be made public (maybe the others as well), as currently to access them from another module I need to do this abomination - .spell_number(num, nil, nil, false, false, false, true, false, nil, nil, nil, nil, false) (just to get the true 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 _numeral_to_english 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)[reply]

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)[reply]
Sorry @Johnuniq:, 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 numeral_to_english_less_1000 (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 numeral_to_ordinal_less_1000 that takes a number would be exactly what I need (and it can then pass to numeral_to_english_less_1000 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 scientific_notation_to_decimal. Hope I answered your questions. --Gonnym (talk) 10:16, 3 November 2018 (UTC)[reply]