Open main menu
Home
Random
Donate
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:BaseConvert/doc
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
Converts numbers to a specified base between 2 and 36, for use in templates such as {{tl|binary}}, {{tl|octal}}, {{tl|hexadecimal}}, etc. ==Usage== <syntaxhighlight lang="lua"> local BaseConvert = require('Module:BaseConvert') BaseConvert.convert({n = 14600926, base = 16}) -- returns 'DECADE' </syntaxhighlight> 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 <code>0x</code> when converting to hex, or a suffix of <code><nowiki><sub>8</sub></nowiki></code> when converting to octal. ===From templates=== In wikimarkup, this module may be called with a function name <code>''n''to''m''</code>, e.g.: {{Markup |<nowiki>{{#invoke:BaseConvert|16to10| FF }}</nowiki>|{{#invoke:BaseConvert|16to10| FF }} |<nowiki>{{#invoke:BaseConvert|10to36|500}}</nowiki>|{{#invoke:BaseConvert|10to36|500}} |<nowiki>{{#invoke:BaseConvert|10to16|Foo|default=0}}</nowiki>|{{#invoke:BaseConvert|10to16|Foo|default=0}}}} All options above are supported, excluding {{para|base}}, {{para|from}} and {{para|n}} which are set by the mandatory options. You may also call <code>convert</code> which is near-identical to the Lua form above. {{Math templates}} <includeonly>[[Category:Wikipedia utility modules]]</includeonly>
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Markup
(
edit
)
Template:Math templates
(
edit
)
Template:Para
(
edit
)
Template:Tl
(
edit
)