| 1 | /** |
| 2 | * @license Fraction.js v2.7.0 01/06/2015 |
| 3 | * http://www.xarg.org/2014/03/rational-numbers-in-javascript/ |
| 4 | * |
| 5 | * Copyright (c) 2015, Robert Eisele ([email protected]) |
| 6 | * Dual licensed under the MIT or GPL Version 2 licenses. |
| 7 | **/ |
| 8 | |
| 9 | function toFraction(frac) { |
| 10 | |
| 11 | var map = { |
| 12 | '1:4': "¼", |
| 13 | '1:2': "½", |
| 14 | '3:4': "¾", |
| 15 | '1:7': "⅐", |
| 16 | '1:9': "⅑", |
| 17 | '1:10': "⅒", |
| 18 | '1:3': "⅓", |
| 19 | '2:3': "⅔", |
| 20 | '1:5': "⅕", |
| 21 | '2:5': "⅖", |
| 22 | '3:5': "⅗", |
| 23 | '4:5': "⅘", |
| 24 | '1:6': "⅙", |
| 25 | '5:6': "⅚", |
| 26 | '1:8': "⅛", |
| 27 | '3:8': "⅜", |
| 28 | '5:8': "⅝", |
| 29 | '7:8': "⅞" |
| 30 | }; |
| 31 | return map[frac.n + ":" + frac.d] || frac.toFraction(false); |
| 32 | } |
| 33 | console.log(toFraction(new Fraction(0.25))); // ¼ |