Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
7425 Lượt xem

i to all,

how to round 2 decimals, even if the value are 00

example : 12.00 

can i do this on python

regards 

Ảnh đại diện
Huỷ bỏ

We can achieve using python using help of "%.2f" format specifier. Can you explain more your requirement ? where you want to put 2 decimal ? i.e. inside any report or inside any web form etc...

Câu trả lời hay nhất

Python only displays what's needed, so it displated 10.0

If it's the matter of printing it as 10.00.

To do that.

>>> d = 10
>>> print "Value: %.2f" % float(d)
Value: 10.00
>>>

Hope this will help you.

Ảnh đại diện
Huỷ bỏ
Tác giả

thanks Parikshit :)

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 1 24
4490
1
thg 8 15
3149
2
thg 3 15
4496
1
thg 3 15
31768
1
thg 3 15
3826