Anonymous
×
Create a new article
Write your page title here:
We currently have 205 articles on Shadowrun Seattle Shutdown. Type your article name above or click on one of the titles below and start writing!



Shadowrun Seattle Shutdown

Module:BaseConvert/doc

< Module:BaseConvert
Revision as of 18:15, 21 December 2023 by Arcology Expert Program (talk | contribs) (→‎Edge cases)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This is the documentation page for Module:BaseConvert

Converts numbers to a specified base between 2 and 36, for use in templates such as Template:Base16 and others.

Usage

local BaseConvert = require('Module:BaseConvert')
BaseConvert.convert({n = 14600926, base = 16}) -- returns 'DECADE'

Arguments:

  • n - (required) the number to be converted, as a string. It may be a number instead, if the input base is 10.
  • base - (required) the base to which the number should be converted. May be between 2 and 36, inclusive.
  • from - the base of the input. Defaults to 10 (or 16 if the input has a leading '0x'). Note that bases other than 10 are not supported if the input has a fractional part.
  • precision - number of digits to be rendered after the radix point. Trailing zeros will be added if needed. If not specified, however many digits are needed will be shown, up to 10.
  • width - minimum number of digits to be rendered before the radix point. Leading zeros will be added if needed.
  • default - Value to return if n is empty or non-numeric. Defaults to the value of n.
  • prefix / suffix - wikitext to add before/after the returned result. Will not be added if n is empty or non-numeric. For example, you might use a prefix of 0x when converting to hex, or a suffix of <sub>8</sub> when converting to octal.

From templates

In wikimarkup, this module may be called with a function name ntom, e.g.:

{{#invoke:BaseConvert|16to10| FF }} returns:

255

{{#invoke:BaseConvert|10to36|500}} returns:

DW

{{#invoke:BaseConvert|10to16|Foo|default=0}} returns:

0

Edge cases

{{#invoke:BaseConvert|10to10|500}} returns:

500

{{#invoke:BaseConvert|10to10|FooBar}} returns:

FooBar

{{#invoke:BaseConvert|10to10|FooBar|default=}} returns:

{{#invoke:BaseConvert|10to16|Foo}} returns:

Foo