# 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.

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.

add a comment

3

There 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 !

1

0

I've posted an alternate answer to the question at the link above. The basic answer: I ran across another way that's posted here 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

nsimplify is much more subtle and does not always return a rational as with nsimplify(3.2352)

Asked: **
2013-09-15 05:29:57 -0500
**

Seen: **719 times**

Last updated: **Sep 15 '13**

Get a matrix to display answers as decimals/floats, not fraction?

Display decimal as a fraction?

How converting some number of different base to 10 to base 10?

how to run fraction elenment in Multivariate Polynomial Ring in over Finite Field ring

How to Rationalize the Denominator of a Fraction ?

divide numerator and denominator by certain value

partial fraction decomposition function for multivariate rational expressions

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.