Decimal to Fraction Calculator

You can use MATLAB's rat() function to obtain a rational approximation of a decimal value. For example, rat(0.625) gives a representation equivalent to 5/8. If you simply want to verify decimal/fraction conversions without running MATLAB, a browser-based decimal-to-fraction calculator can also be useful.
Neerudi Bhoopal
Neerudi Bhoopal on 31 Aug 2026
Floating-point form is generally preferred for numerical computation, while rational form is useful for interpretation, pattern recognition, and mathematical presentation.
John D'Errico
John D'Errico on 29 Aug 2026 (Edited on 29 Aug 2026)
And of course, rat also gives us some juicy tidbits, like these classic rational approximations for pi.
[N,D] = rat(pi,0.01)
N = 22
D = 7
[N,D] = rat(pi) % the default tolerance
N = 355
D = 113
And even a not so good approximation.
[N,D] = rat(pi,1) % The lazy schoolboard approximation
N = 3
D = 1
When I wear my numerical analyst hat, it is not too often I want to work in rational form, because usually I need floating point numbers without that rational approximation. But sometimes rational approximations are important to see what is happening. And of course, sometimes the rat format is nice to have too.
format rat
hilb(5)
ans =
1 1/2 1/3 1/4 1/5 1/2 1/3 1/4 1/5 1/6 1/3 1/4 1/5 1/6 1/7 1/4 1/5 1/6 1/7 1/8 1/5 1/6 1/7 1/8 1/9
You can also use sym to get that rational form.
sym(0.625)
Walter Roberson
Walter Roberson on 31 Aug 2026
I disagree. When I wear my numerical analyst hat, I immediately convert to rational form, such as 0.4192 converted to (sym(4192)/sym(10)^4 + delta_c1) where delta_c1 is constrained to -sym(5)/sym(10)^5 inclusive to sym(5)/sym(10)^5 exclusive . It is only by working with the rational forms that we can analyze what the expressions really mean.
If (for example) 0.4192 appears in a floating point expression, we cannot understand it as being 0.4192 +/- eps(0.4192): we need to understand it as being 0.41915 inclusive to 0.41925 exclusive -- otherwise it would have been written as 0.4192000000000
John D'Errico
John D'Errico on 29 Aug 2026 (Edited on 29 Aug 2026)
Strangely, sym did not show the result, even though it was visible as I was editting.
sym(0.625)

Tags

No tags entered yet.