ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 16 Sep 2013 02:12:34 -0500Decimal to fraction?http://ask.sagemath.org/question/10540/decimal-to-fraction/I did .1/8, and the output was 0.0125000000. Is there a way to get it to display as 1/80.Sun, 15 Sep 2013 05:29:57 -0500http://ask.sagemath.org/question/10540/decimal-to-fraction/Answer by ppurka for <p>I did .1/8, and the output was 0.0125000000. Is there a way to get it to display as 1/80.</p>
http://ask.sagemath.org/question/10540/decimal-to-fraction/?answer=15454#post-id-15454Dupe of http://ask.sagemath.org/question/2758/display-decimal-as-a-fractionSun, 15 Sep 2013 06:20:25 -0500http://ask.sagemath.org/question/10540/decimal-to-fraction/?answer=15454#post-id-15454Comment by vdelecroix for <p>Dupe of <a href="http://ask.sagemath.org/question/2758/display-decimal-as-a-fraction">http://ask.sagemath.org/question/2758...</a></p>
http://ask.sagemath.org/question/10540/decimal-to-fraction/?comment=17012#post-id-17012it is fun as also the answers are duplicate ;-)Mon, 16 Sep 2013 02:12:34 -0500http://ask.sagemath.org/question/10540/decimal-to-fraction/?comment=17012#post-id-17012Answer by dazedANDconfused for <p>I did .1/8, and the output was 0.0125000000. Is there a way to get it to display as 1/80.</p>
http://ask.sagemath.org/question/10540/decimal-to-fraction/?answer=15458#post-id-15458I've posted an alternate answer to the question at the [link above](http://ask.sagemath.org/question/2758/display-decimal-as-a-fraction). The basic answer: I ran across another way that's posted [here](http://www.johndcook.com/blog/2013/04/30/recognizing-numbers/) where the author, John D Cook mentions the `nsimplify` command in SymPy (which you can can access in Sage). Here's `nsimplify` in action with your example
![image description](/upfiles/13792730101525131.jpg)Sun, 15 Sep 2013 09:24:34 -0500http://ask.sagemath.org/question/10540/decimal-to-fraction/?answer=15458#post-id-15458Comment by vdelecroix for <p>I've posted an alternate answer to the question at the <a href="http://ask.sagemath.org/question/2758/display-decimal-as-a-fraction">link above</a>. The basic answer: I ran across another way that's posted <a href="http://www.johndcook.com/blog/2013/04/30/recognizing-numbers/">here</a> where the author, John D Cook mentions the <code>nsimplify</code> command in SymPy (which you can can access in Sage). Here's <code>nsimplify</code> in action with your example
<img alt="image description" src="/upfiles/13792730101525131.jpg"/></p>
http://ask.sagemath.org/question/10540/decimal-to-fraction/?comment=17013#post-id-17013nsimplify is much more subtle and does not always return a rational as with nsimplify(3.2352)Mon, 16 Sep 2013 02:11:38 -0500http://ask.sagemath.org/question/10540/decimal-to-fraction/?comment=17013#post-id-17013Answer by tmonteil for <p>I did .1/8, and the output was 0.0125000000. Is there a way to get it to display as 1/80.</p>
http://ask.sagemath.org/question/10540/decimal-to-fraction/?answer=15456#post-id-15456There are at least three ways to recover a rational from one of its numerical approximations:
sage: a = .1/8
sage: a.simplest_rational()
1/80
sage: a.nearby_rational(0.0001)
1/80
sage: a.exact_rational()
3602879701896397/288230376151711744
You can have a look to their respective documentations to see the differences. And you should understand that the floating point number `a` is not equal to 1/80 but to 3602879701896397/288230376151711744 !Sun, 15 Sep 2013 06:20:29 -0500http://ask.sagemath.org/question/10540/decimal-to-fraction/?answer=15456#post-id-15456