I've added the following information to the Sage Essentials page on formatting the numbers in Sage output:

**Formatting numbers**

Chances are you'll find Sage gives you a number in a format that doesn't look very nice. You can change the formatting by converting the number to a string and then using the formatting options for string to clean up the representation. Run the following code:

print("The square root of 2: "+str(sqrt(2)))#Print sqrt(2) symbolically

a=float(sqrt(2))#force sqrt(2) to a floating point number

print("The square root of 2 is "+str(a)+"but now you might not like the format of the number.")#Print the number

print("To control the format of the number, try: The square root of 2 is {0:.3f}".format(a))#print 3 digits after decimal

b=float(sqrt(3))

c=float(a+b)

print("Multiple arguments can also be handled: the sqrt(2)+sqrt(3) is just {0:.5f} + {1:.5f} = {2:.5f}".format(a,b,c))

and you'll get this output:

$latex \sqrt{2}$ is represented symbolically as sqrt(2) until it is converted to a floating a point number with:

a=float(sqrt(2))#force sqrt(2) to a floating point number

at which point now you have Sage deciding for you how the decimal is represented. You can tell Sage how you want your numbers displayed using the format method of Python as explained in detail here. The key line in our code above is

print("Multiple arguments can also be handled: the sqrt(2)+sqrt(3) is just {0:.5f} + {1:.5f} = {2:.5f}".format(a,b,c))print("Multiple arguments can also be handled: the sqrt(2)+sqrt(3) is just {0:.5f} + {1:.5f} = {2:.5f}".format(a,b,c))

There are 3 numbers used in the print statement, referred to as 0, 1, and 2. When it's time to print a number we give instruction as to how the number should be formatted. The argument {0:.5f} instructs that the 0th number should show 5 digits after the decimal. After instructing what the format will be for each number you finish it off with the format(a,b,c) to define a as the 0th number, b as the first number, and c as the 2nd number. As the Python documentation tells us, decimals can be represented as fixed point (f), exponential (e), general format (g), n as number and % as percents.

Older methods of string format still work but are being deprecated so use the format method.