tag:blogger.com,1999:blog-7008397742323047118.post8980979939712090648..comments2020-01-20T01:59:41.294-08:00Comments on Shawn Driscoll's Tech Blog: Printing Formatted Floats in PythonShawn Driscollhttp://www.blogger.com/profile/05570554975738301255noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-7008397742323047118.post-7480156493969153272012-07-27T21:44:02.482-07:002012-07-27T21:44:02.482-07:00I'm starting to see. The first number is the ...I'm starting to see. The first number is the total number of digits (not just the number of digits on the left of the decimal). Maybe that was my mistake? I'll try again.Shawn Driscollhttps://www.blogger.com/profile/05570554975738301255noreply@blogger.comtag:blogger.com,1999:blog-7008397742323047118.post-48155775911905072972012-07-27T20:32:11.965-07:002012-07-27T20:32:11.965-07:00HTML formatting is going to mess around with the n...HTML formatting is going to mess around with the number of spaces in the output string, but you should be able to cut-n-paste the Python lines into a shell and see the results. I think this is what you're looking for but correct me if I'm wrong. You can do something similar in C.<br /><br />>>> import math<br />>>> math.pi<br />3.141592653589793<br />>>> '%10.2f' % math.pi<br />' 3.14'<br />>>> '%8.4f' % math.pi<br />' 3.1416'<br />>>> '%12.1f' % math.pi<br />' 3.1'wescpyhttps://www.blogger.com/profile/08896306361304265422noreply@blogger.com