how to get output in a mixed fraction?
regular rational sage style is like
sage:22/10
i want make it look like (thru pprint it will just look like a mixed on papper)
sage:2+2/10
is this possible?
regular rational sage style is like
sage:22/10
i want make it look like (thru pprint it will just look like a mixed on papper)
sage:2+2/10
is this possible?
If you want all rational numbers to look like this, then there isn't a convenient way to make that happen in Sage. I'm currently working on a framework to allow one to do this, but it's not ready yet. I will update this post when there is a ticket in question
However, if you just want a function that will return a string in the right form, you can use something like the following
def pprint(rational):
if rational < 0:
return '%s - %s'%(rational.ceil(), rational.ceil() - rational)
elif rational > 0:
return '%s + %s'%(rational.floor(), rational-rational.floor())
else:
return '0'
Can you say a bit more about this framework? Is it a printing framework?
yeah would be great to deal this without that much complex constructions..
got an easier solution btw
sage: a=22/10 sage: floor(a), a - floor(a) (2, 1/5)
Note that if a is something like -22/10, that will give (-3, -4/5) which is probably not the desired result.
Please start posting anonymously - your entry will be published after you log in or create a new account.
Asked: 2010-08-21 14:27:07 +0100
Seen: 3,313 times
Last updated: Aug 21 '10
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.