Module:BaseConvert/doc
This is a documentation subpage for Module:BaseConvert. It may contain usage information, categories and other content that is not part of the original module page. |
මෙම Lua module පිටු 34,000 පමණ භාවිතා වන නිසා සිදුකරන වෙනස් කිරීම් බොහෝ ස්ථානවලට බලපානු ඇත. ඔබ සිදුකිරීමට අදහස් කරන වෙනස්කම් මෙම මොඩියුලයට අදාළ /sandbox හෝ /testcases උපපිටු. එම වෙනස්කම් සිදුකිරීමට ප්රථම අදාළ සාකච්ඡා පිටුවේ ඒ පිළිබඳව සංවාදයක් ගොඩනැගීමට කාරුණික වන්න.
Transclusion count updated automatically (ප්රලේඛනය වෙතට යොමුවන්න). |
Converts numbers to a specified base between 2 and 36, for use in templates such as {{Binary}}, {{Octal}}, {{Hexadecimal}}, etc.
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.:
Markup | Renders as |
---|---|
{{#invoke:BaseConvert|16to10| FF }} |
255 |
{{#invoke:BaseConvert|10to36|500}} |
DW |
{{#invoke:BaseConvert|10to16|Foo|default=0}} |
0
|
All options above are supported, excluding |base=
, |from=
and |n=
which are set by the mandatory options.
Edge cases
සංස්කරණයMarkup | Renders as |
---|---|
{{#invoke:BaseConvert|10to10|500}} |
500 |
{{#invoke:BaseConvert|10to10|FooBar}} |
FooBar |
{{#invoke:BaseConvert|10to10|FooBar|default=}} |
|
{{#invoke:BaseConvert|10to16|Foo}} |
Foo
|