Ask Your Question
0

Decimal to fraction?

asked 2013-09-15 12:29:57 +0200

bxdin gravatar image

I did .1/8, and the output was 0.0125000000. Is there a way to get it to display as 1/80.

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
3

answered 2013-09-15 13:20:29 +0200

tmonteil gravatar image

updated 2013-09-15 13:33:41 +0200

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 !

edit flag offensive delete link more
1

answered 2013-09-15 13:20:25 +0200

ppurka gravatar image
edit flag offensive delete link more

Comments

it is fun as also the answers are duplicate ;-)

vdelecroix gravatar imagevdelecroix ( 2013-09-16 09:12:34 +0200 )edit
0

answered 2013-09-15 16:24:34 +0200

dazedANDconfused gravatar image

updated 2013-09-15 18:51:13 +0200

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 image description

edit flag offensive delete link more

Comments

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

vdelecroix gravatar imagevdelecroix ( 2013-09-16 09:11:38 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2013-09-15 12:29:57 +0200

Seen: 1,821 times

Last updated: Sep 15 '13