Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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'