0.875 as fraction calculator that works anywhere
Question: What is 0.875 written as a fraction
Answer: 0.875 can be written as 7/8
Decimal to fraction calculator - 0.875 to 7/8
Click on the snippet below to see how you can convert decimals to fractions as you type.
Decimal to fraction calculator
{formtext: name=number; default=0.875} is {if: isnumber(number) = "yes"}{if: number <> floor(number)}
{note: preview=no; trim=yes}
{int=split(number, ".")[1] if split(number, ".")[1] <> "" else 0}{decimals=split(number, ".")[2]}
{numerator=extractregex(decimals, "\d{0,3}")}
{denominator=10^len(numerator)}
{factors1=filter([numerator/i for i in seq(1, numerator)], item -> testregex(item, "\.") = "no")}
{factors2=filter([denominator/i for i in seq(1, denominator)], item -> testregex(item, "\.") = "no")}
{gcf=filter(factors1, item -> includes(factors2, item) = "yes")[1]}
{endnote: trim=right}
{if: int > 0}{=catch(int, "")} {endif}{=numerator/gcf}/{=denominator/gcf}
{else}
{=abs(number)}
{endif}
{else}
{error: Please input a number}
{endif}
_
Just give me the fraction!
Need to just type fraction? No problem! The snippet below behaves exactly like the snippet above, but the output is just the fraction.
Decimal to fraction calculator - just the fraction
{note}{formtext: name=number; default=0.875}{endnote}{if: isnumber(number) = "yes"}{if: number <> floor(number)}
{note: preview=no; trim=yes}
{int=split(number, ".")[1] if split(number, ".")[1] <> "" else 0}{decimals=split(number, ".")[2]}
{numerator=extractregex(decimals, "\d{0,3}")}
{denominator=10^len(numerator)}
{factors1=filter([numerator/i for i in seq(1, numerator)], item -> testregex(item, "\.") = "no")}
{factors2=filter([denominator/i for i in seq(1, denominator)], item -> testregex(item, "\.") = "no")}
{gcf=filter(factors1, item -> includes(factors2, item) = "yes")[1]}
{endnote: trim=right}
{if: int > 0}{=catch(int, "")} {endif}{=numerator/gcf}/{=denominator/gcf}
{else}
{=abs(number)}
{endif}
{else}
{error: Please input a number}
{endif}
_
How decimal to fraction conversion works
- Write down the decimal - we'll focus on decimals that terminate (the calculator above uses up to 3 decimal places)
- Divide the decimal by 1 to create a fraction that looks like this: 0.875 / 1
- Multiply both numerator and denominator by 10 until you get a regular fraction: 875 / 1000
- Divide both by the largest common denominator: (875 / 125) / (1000 / 125) = 7 / 8
Hi there! You made it all the way down to the bottom of this article. Take a few seconds to share it.
Want to turbo charge your work with templates and snippets? Text Blaze is the fastest way to do that.