Skip to content

Instantly share code, notes, and snippets.

@jansim
Last active May 4, 2022 02:33
Show Gist options
  • Save jansim/f58c734988de38d30468bf7c57f6669c to your computer and use it in GitHub Desktop.
Save jansim/f58c734988de38d30468bf7c57f6669c to your computer and use it in GitHub Desktop.
Unicode Vulgar Fractions in JavaScript / JSON
// Vulgar fractions are Unicode characters for specific fractions i.e. ½
// List of fractions from: https://stackoverflow.com/questions/35012491/parse-%C2%BD-as-0-5-in-python-2-7
// See also: http://unicodefractions.com/
// Calculate fractions on-the-fly
const vulgar_fractions = {
'\u2189': 0/3,
'\u2152': 1/10,
'\u2151': 1/9,
'\u215B': 1/8,
'\u2150': 1/7,
'\u2159': 1/6,
'\u2155': 1/5,
'\u00BC': 1/4,
'\u2153': 1/3,
'\u215C': 3/8,
'\u2156': 2/5,
'\u00BD': 1/2,
'\u2157': 3/5,
'\u215D': 5/8,
'\u2154': 2/3,
'\u00BE': 3/4,
'\u2158': 4/5,
'\u215A': 5/6,
'\u215E': 7/8
}
// Computed fraction values
const vulgar_fractions = {
'\u2189': 0.0,
'\u2152': 0.1,
'\u2151': 0.11111111,
'\u215B': 0.125,
'\u2150': 0.14285714,
'\u2159': 0.16666667,
'\u2155': 0.2,
'\u00BC': 0.25,
'\u2153': 0.33333333,
'\u215C': 0.375,
'\u2156': 0.4,
'\u00BD': 0.5,
'\u2157': 0.6,
'\u215D': 0.625,
'\u2154': 0.66666667,
'\u00BE': 0.75,
'\u2158': 0.8,
'\u215A': 0.83333333,
'\u215E': 0.875
}
{
"\u2189": 0.0,
"\u2152": 0.1,
"\u2151": 0.11111111,
"\u215B": 0.125,
"\u2150": 0.14285714,
"\u2159": 0.16666667,
"\u2155": 0.2,
"\u00BC": 0.25,
"\u2153": 0.33333333,
"\u215C": 0.375,
"\u2156": 0.4,
"\u00BD": 0.5,
"\u2157": 0.6,
"\u215D": 0.625,
"\u2154": 0.66666667,
"\u00BE": 0.75,
"\u2158": 0.8,
"\u215A": 0.83333333,
"\u215E": 0.875
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment