#!/usr/bin/env python3
###################################################################################
# Python function to format a number
###################################################################################
print("Content-Type: text/html \n")     #http header with newline char (required for the web)

variable1 = 10/4
variable2 = 75.6667
 
print('<pre>')                          #to produce better display on the web 

print("===OPTION 1=====================")
print(" %.2f "  %  1234.5 )						                    # 1234.50
print("Num: %5.2f and $%6.3f"  %  (variable1, variable2) )		    # Num:  2.50 and $75.667

print("===OPTION 2=====================")
print(" {:.2f}".format(1234.5) )						            # 1234.50
print("Num: {:5.2f} and ${:6.3f}".format(variable1,variable2) )	    # Num:  2.50 and $75.667

print("===OPTION 3 (best) =============")
print( F" {1234.5 :.2f}" )						                    # 1234.50
print( F"Num: {variable1 :5.2f} and ${variable2 :6.3f}")		    # Num:  2.50 and $75.667
print()

var = 1234567.89

print (F'{var :,}')                 #format with commas
print (F'{var :.0f}')               #format with 0 decimal places
print (F'{var :.3f}')               #format with 3 decimal places
print (F'{var :,.3f}')              #format with commas and 3 decimal places
print (F'{var :+.3f}')              #format with + for positive numbers
print (F'{var :<15,.2f}')           #left align  15 characters total with commas
print (F'{var :>15,.2f}')           #right align 15 characters total with commas
print (F'{var :0>15.2f}')           #right align 15 chars with leading zeros
print (F'{var :$>15.2f}')           #right align 15 chars with leading $ signs
print()

formatted = F"{var :$>15,.2f}"	    #formatting and assigning to a variable
print(formatted)					# '$$$1,234,567.89'