return the numerator and denimentor
2 次查看(过去 30 天)
显示 更早的评论
Hi everyone
Is there such a way to return the numerator and the denomenator of a given rational number
for example x = 1/2
I want to get n=1 , d=2
0 个评论
采纳的回答
John D'Errico
2019-12-9
Rat gives rational results for a floating point number, sometimes they are only approximate, of course.
[n,d] = rat(1/2)
n =
1
d =
2
[n,d] = rat(pi)
n =
355
d =
113
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interpolation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!