|
Last change
on this file since 505f39a was 2058e5c, checked in by istevanoska <ilinastevanoska@…>, 6 months ago |
|
Working / before login
|
-
Property mode
set to
100644
|
|
File size:
701 bytes
|
| Line | |
|---|
| 1 | /*
|
|---|
| 2 | Fraction.js v5.0.0 10/1/2024
|
|---|
| 3 | https://raw.org/article/rational-numbers-in-javascript/
|
|---|
| 4 |
|
|---|
| 5 | Copyright (c) 2024, Robert Eisele (https://raw.org/)
|
|---|
| 6 | Licensed under the MIT license.
|
|---|
| 7 | */
|
|---|
| 8 |
|
|---|
| 9 | const Fraction = require('fraction.js');
|
|---|
| 10 |
|
|---|
| 11 | function toFraction(frac) {
|
|---|
| 12 |
|
|---|
| 13 | var map = {
|
|---|
| 14 | '1:4': "¼",
|
|---|
| 15 | '1:2': "½",
|
|---|
| 16 | '3:4': "¾",
|
|---|
| 17 | '1:7': "⅐",
|
|---|
| 18 | '1:9': "⅑",
|
|---|
| 19 | '1:10': "⅒",
|
|---|
| 20 | '1:3': "⅓",
|
|---|
| 21 | '2:3': "⅔",
|
|---|
| 22 | '1:5': "⅕",
|
|---|
| 23 | '2:5': "⅖",
|
|---|
| 24 | '3:5': "⅗",
|
|---|
| 25 | '4:5': "⅘",
|
|---|
| 26 | '1:6': "⅙",
|
|---|
| 27 | '5:6': "⅚",
|
|---|
| 28 | '1:8': "⅛",
|
|---|
| 29 | '3:8': "⅜",
|
|---|
| 30 | '5:8': "⅝",
|
|---|
| 31 | '7:8': "⅞"
|
|---|
| 32 | };
|
|---|
| 33 | return map[frac.n + ":" + frac.d] || frac.toFraction(false);
|
|---|
| 34 | }
|
|---|
| 35 | console.log(toFraction(Fraction(0.25))); // ¼
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.