# Display decimal as a fraction?

The number 1.5 represents 3/2 in decimal form.

In sage I can get 3/2 to display as a decimal: 3/2.n()

I haven't had any luck converting 1.5 to a fraction.

Display decimal as a fraction?

The number 1.5 represents 3/2 in decimal form.

In sage I can get 3/2 to display as a decimal: 3/2.n()

I haven't had any luck converting 1.5 to a fraction.

add a comment

5

You can try:

```
sage: QQ(1.5)
3/2
```

or:

```
sage: (1.5).exact_rational()
3/2
```

As a warning, i let you undertand the following behaviour with decimal numbers:

```
sage: (1.1).exact_rational()
2476979795053773/2251799813685248
```

2

3

Indeed. 4/3 is not a floating-point number since it can not be written as `p/2^q`. So, when you write sage: a = RR(4/3) You only get an approximation of `4/3`, whose value is sage: a.exact_rational() 6004799503160661/4503599627370496 If you want to recover `4/3` from `a`, you can do sage: a.simplest_rational() 4/3 or, sage: QQ(a) 4/3 But you should understand that two roundings were done during your computation, and that you may have lost something there.

1

`nsimplify`

command in SymPy (which you can can access in Sage). As the post indicates, you can suggest constants (eg pi) that should be considered and "...can also give nsimplify a tolerance, asking it to find a simple representation within a neighborhood of the number". Here's a screenshot of it recognizing 1.3333333333333 in a Sage Cell Server.

0

answered
**
2016-02-29 18:59:46 -0500
**

This post is a wiki. Anyone with karma >750 is welcome to improve it.

1.5 equals to 1 1/2 .

Asked: **
2013-06-30 13:32:27 -0500
**

Seen: **7,561 times**

Last updated: **Sep 15 '13**

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.