ᱪᱷᱟᱸᱪ:Rndfrac/doc
ᱧᱮᱞᱚᱜ
This is a documentation subpage for ᱪᱷᱟᱸᱪ:Rndfrac. It contains usage information, categories and other content that is not part of the original ᱪᱷᱟᱸᱪ page. |
This template rounds to a fraction. It takes two parameters.
- the number to be rounded (any real number)
- the denominator to be rounded to (positive integer)
Fractions are expressed in the simplest terms.
The template calls {{gcd}} and {{rndfrac/out}}.
{{rndfrac|0.1234|8}}
→ ᱑⁄᱘{{rndfrac|12.65|6}}
→ ᱑᱒&#᱓᱒;᱔⁄᱖{{rndfrac|-9.123|20}}
→ −᱙&#᱓᱒;᱒⁄᱒᱐
Code
[ᱯᱷᱮᱰᱟᱛ ᱥᱟᱯᱲᱟᱣ]Main template {{rndfrac}}
{{#ifexpr: ( {{{2}}} - 1 ) round 0 = abs( {{{2}}} - 1 )
| {{#ifexpr: {{{1}}} * {{{2}}} round 0 < 0
|−
}}{{formatnum: {{rndfrac/{{{out|out}}}
| {{#expr: floor( (abs {{{1}}} * {{{2}}} round 0 ) / {{{2}}} ) }}
| {{#expr: (abs {{{1}}} * {{{2}}} round 0 ) mod {{{2}}} }}
| {{{2}}}
| {{gcd | {{#expr: (abs {{{1}}} * {{{2}}} round 0 ) mod {{{2}}} }}
| {{{2}}}
}}
}}
}}
| {{color | red | This fractional rounding function only accepts positive intergers as the denominator. }}
}}
Sub-template {{rndfrac/out}}
{{#ifeq: {{{2}}} | 0
| {{{1}}}
| <span class="frac nowrap">{{#ifexpr: {{{1}}} > 0
| {{{1}}}<sup> </sup>
}}{{#iferror: {{#expr: 1/{{{4}}} }}
| <sup>{{{2}}}</sup>⁄<sub>{{{3}}}</sub>
| <sup>{{#expr: {{{2}}} / {{{4}}} }}</sup>⁄<sub>{{#expr: {{{3}}} / {{{4}}} }}</sub>
}}
</span>
}}
See also
[ᱯᱷᱮᱰᱟᱛ ᱥᱟᱯᱲᱟᱣ]- {{rnd}}
- {{rndnear}}
- {{dec to frac}}