Difference between revisions of "Template:Dec to frac"

From MidsouthMakers - Memphis Area Hackerpace
Jump to navigation Jump to search
m (1 revision)
 
(No difference)

Latest revision as of 17:53, 18 January 2010

[edit] [purge] Template documentation

This template converts a decimal fraction to a vulgar fraction which is equal to the result of rounding to a multiple of one divided by a given denominator. 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, but due to algorithm limitation fractions with relatively large nominators/denominators may be left unresolved.

Examples

  • {{dec to frac|0.375|16}} →  38
  • {{dec to frac|0.375|100}} →  1950
  • {{dec to frac|3.6742|16}} → 3 1116
  • {{dec to frac|3.99|8}} → 4
  • {{dec to frac|3.1|2}} → 3

To reduce rounding errors, increase the denominator:

  • {{dec to frac|0.375|1000}} →  38
  • {{dec to frac|3.6742|64}} → 3 4364
  • {{dec to frac|3.99|80}} → 3 7980
  • {{dec to frac|3.1|10}} → 3 110