User Tools

Site Tools


print_hundredths

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
round_vs._format [2023/02/08 16:26] rajuprint_hundredths [2023/02/14 20:45] – removed - external edit (Unknown date) 127.0.0.1
Line 1: Line 1:
-==== round vs. format ==== 
-<code> 
-$ ipython 
-Python 3.10.9 | packaged by conda-forge | (main, Jan 11 2023, 15:15:40) [MSC v.1916 64 bit (AMD64)] 
-IPython 8.8.0 -- An enhanced Interactive Python. Type '?' for help. 
- 
-In [1]: 
-a = 10.30467 
- 
-In [2]: 
-'{:.2f}'.format(a) 
-Out[2]: 
-'10.30' 
- 
-In [3]: 
-type('{:.2f}'.format(a)) 
-Out[3]: 
-str 
- 
-In [4]: 
-round(a,2) 
-Out[4]: 
-10.3 
- 
-In [5]: 
-type(round(a,2)) 
-Out[5]: 
-float 
-</code> 
- 
-Conclusions: 
-  * The output of round is a floating point number. The output of format is a string 
-  * To output dollars and pennies, format expression is better than rounding as it always gives the same number of digits after the decimal point. 
  
print_hundredths.txt · Last modified: 2023/02/14 23:26 by raju