Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
6875 มุมมอง

i to all,

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

example : 12.00 

can i do this on python

regards 

อวตาร
ละทิ้ง

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...

คำตอบที่ดีที่สุด

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.

อวตาร
ละทิ้ง
ผู้เขียน

thanks Parikshit :)

Related Posts ตอบกลับ มุมมอง กิจกรรม
How to make tree of dictionary? แก้ไขแล้ว
1
ม.ค. 24
3854
1
ส.ค. 15
2599
2
มี.ค. 15
3809
1
มี.ค. 15
31142
1
มี.ค. 15
3402