开发者

Convert float 27.7 to 27.70 [closed]

开发者 https://www.devze.com 2023-01-25 15:58 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its curr开发者_StackOverflowent
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its curr开发者_StackOverflowent form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

can anyone tell me a simple way to print out a float 27.7 as 27.70 ?

thanks.


a = 27.7
print '%.2f' % a
27.70


If you're worrying about number of digits after point, you probably need use decimal.Decimal Cite from the docs:

Decimal numbers can be represented exactly. In contrast, numbers like 1.1 and 2.2 do not have an exact representations in binary floating point. End users typically would not expect 1.1 + 2.2 to display as 3.3000000000000003 as it does with binary floating point.

0

精彩评论

暂无评论...
验证码 换一张
取 消