Jump to content

Template:Dec to frac: Difference between revisions

From IdeaWazaWiki
wikademia>Ezhiki
+doc
wikademia>Ezhiki
filter out integer input
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
<includeonly><small>{{frac|{{#ifexpr:{{floor|{{{1}}}}}<>0|{{floor|{{{1}}}}}}}|{{#expr:((({{#expr:{{{1}}}-{{floor|{{{1}}}}}}})*{{{2}}}) round 0)/{{gcd|((({{#expr:{{{1}}}-{{floor|{{{1}}}}}}})*{{{2}}}) round 0)|{{{2}}}}}}}|{{#expr:{{{2}}}/{{gcd|((({{#expr:{{{1}}}-{{floor|{{{1}}}}}}})*{{{2}}}) round 0)|{{{2}}}}}}}}}</small></includeonly><noinclude>
<includeonly>{{#ifexpr:({{{1}}}-{{floor|{{{1}}})<>0|<small>{{frac|{{#ifexpr:{{floor|{{{1}}}}}<>0|{{floor|{{{1}}}}}}}|{{#expr:((({{#expr:{{{1}}}-{{floor|{{{1}}}}}}})*{{{2}}}) round 0)/{{gcd|((({{#expr:{{{1}}}-{{floor|{{{1}}}}}}})*{{{2}}}) round 0)|{{{2}}}}}}}|{{#expr:{{{2}}}/{{gcd|((({{#expr:{{{1}}}-{{floor|{{{1}}}}}}})*{{{2}}}) round 0)|{{{2}}}}}}}}}</small>|{{{1}}}}}</includeonly><noinclude>
This template converts decimal fractions to vulgar fractions.  It takes two parameters:
This template converts decimal fractions to vulgar fractions.  It takes two parameters:
*fraction to be converted;
*fraction to be converted;
Line 11: Line 11:


==Known issues==
==Known issues==
Since the resulting fraction is the closest of what can be achieved using the supplied denominator, this template may occasionally produce odd results:
Since the resulting fraction is the closest to the decimal fraction of what can be achieved using the requested denominator, this template may occasionally produce odd results:
*<nowiki>{{dec to frac|3.999|9}}</nowiki>&nbsp;&rarr; {{dec to frac|3.999|9}}
*<nowiki>{{dec to frac|3.999|9}}</nowiki>&nbsp;&rarr; {{dec to frac|3.999|9}}


[[Category:Mathematical function templates]]
[[Category:Mathematical function templates|Dec to frac]]
</noinclude>
</noinclude>

Latest revision as of 20:13, 3 August 2007

This template converts decimal fractions to vulgar fractions. It takes two parameters:

  • fraction to be converted;
  • resulting vulgar fraction's denominator

If the decimal fraction includes an integer part, it is retained in the output. If the resulting vulgar fraction can be resolved in lower terms than specified denominator, it is resolved.

Examples

Known issues

Since the resulting fraction is the closest to the decimal fraction of what can be achieved using the requested denominator, this template may occasionally produce odd results: