User:Johan G/convert/rear: Difference between revisions
< User:Johan G | convert
Jump to navigation
Jump to search
(Created page with "{{#if: <!-- Is the to-unit parameter missing? --> {{{1|}}} | <!-- No, the to-unit parameter is not missing -->{{#expr: 188.348149 round {{#ifeq: <!-- Is "decima...") |
(Moving pretty much all but the conversion factors here) |
||
Line 1: | Line 1: | ||
{{#if: <!-- Is the | {{#if: <!-- Is the "value" parameter missing? --> | ||
{{{1|}}} | {{{1|}}} | ||
| <!-- No, the to-unit parameter is not missing | | <!-- No, the "to-unit" parameter is not missing | ||
-->{{#expr: | -->{{#if: <!-- Is the to-unit parameter missing? --> | ||
{{{2|}}} | |||
| <!-- No, the to-unit parameter is not missing | |||
-->{{#expr: {{{1|1000 div 25.4}}} round | |||
{{#ifeq: <!-- Is "decimals" an empty string? --> | |||
{{{3|}}} | |||
| | |||
| 0 <!-- Yes, substitute with zero for no decimals --> | |||
| {{{3}}} <!-- No, use "decimals" decimals --> | |||
}} | |||
}} <!-- | |||
-->{{#if: <!-- Is "hide-unit" not empty? --> | |||
{{{4|}}} | |||
| <!-- Yes, hide "to-unit" --> | |||
| {{{2}}} <!-- No, use "to-unit" --> | |||
}} | |||
| <!-- Yes, the "to-unit" parameter is missing. Throw an error --> | |||
{{error|<nowiki>{{User:Johan G/convert/pds}}</nowiki>: Parameter '''to-unit''' missing}} | |||
}} | }} | ||
| <!-- Yes, the | | <!-- Yes, the "value" parameter is missing. Throw an error --> | ||
{{error|<nowiki>{{User:Johan G/convert/pds}}</nowiki>: Parameter ''' | {{error|<nowiki>{{User:Johan G/convert/pds}}</nowiki>: Parameter '''value''' missing}} | ||
}}<noinclude> | }}<noinclude> | ||
{{Informative template|1= | {{Informative template|1= | ||
__NOTOC__ | __NOTOC__ | ||
== Goal == | == Goal == | ||
This template handles | This template handles rounding, decimals and units for User:Johan G/convert ("rear" is for rear part of the quantity). | ||
{{inote|When this template draft is moved to the template namespace, give it a better name...}} | |||
== Usage == | == Usage == | ||
{{obr}}'''User:Johan G/convert/rear'''{{!}}to-unit{{!}}decimals{{!}}hide-unit{{cbr}} | {{obr}}'''User:Johan G/convert/rear'''{{!}}expression{{!}}to-unit{{!}}decimals{{!}}hide-unit{{cbr}} | ||
The parameters '''expression''' and '''to-unit''' is manatory, though '''all parameters''' should be passed from the main template. | |||
; expression: Expression to be calculated with Extension:ParserFunctions's #expr function | |||
; to-unit: Unit to be converted to | ; to-unit: Unit to be converted to | ||
Line 35: | Line 46: | ||
== Examples == | == Examples == | ||
Conversion from millimeters to inches as it would be used in the main template... | |||
{{obr}}'''User:Johan G/convert/rear'''{{!}}<nowiki>{{{1}}} div 25.4</nowiki>{{!}}<nowiki>in</nowiki>{{!}}<nowiki>{{{4|}}}</nowiki>{{!}}<nowiki>{{{5|}}}</nowiki>{{cbr}} | |||
...with the parameters having these values | |||
{{obr}}'''User:Johan G/convert/rear'''{{!}}<nowiki>1000 div 25.4</nowiki>{{!}}<nowiki>in</nowiki>{{!}}<nowiki>2</nowiki>{{!}}<nowiki></nowiki>{{cbr}} | |||
{{User:Johan G/convert/rear|{{#expr: {{{1|1000}}} div 25.4 }}|{{{3|in}}}|{{{4|3}}}|{{{5|}}}}} | |||
== Known issues == | == Known issues == |
Revision as of 17:40, 6 August 2018
{{User:Johan G/convert/pds}}: Parameter value missing
The following template description is not displayed when the template is inserted in an article.
Goal
This template handles rounding, decimals and units for User:Johan G/convert ("rear" is for rear part of the quantity).
Note When this template draft is moved to the template namespace, give it a better name...
Usage
{{User:Johan G/convert/rear|expression|to-unit|decimals|hide-unit}}
The parameters expression and to-unit is manatory, though all parameters should be passed from the main template.
- expression
- Expression to be calculated with Extension:ParserFunctions's #expr function
- to-unit
- Unit to be converted to
- decimals
- Number of decimals. If empty, no decimals will be shown
- hide-unit
- If not empty the unit will not be shown in the result
Examples
Conversion from millimeters to inches as it would be used in the main template...
{{User:Johan G/convert/rear|{{{1}}} div 25.4|in|{{{4|}}}|{{{5|}}}}}
...with the parameters having these values
{{User:Johan G/convert/rear|1000 div 25.4|in|2|}}
39.37 in
Known issues
Trailing zeros in the decimals will not be shown.
Related templates