开发者

Convert float 27.7 to 27.70 [closed]

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜