Reputation: 117
I would like to add space my print function. Actually it works, so I add space start of line but I have to show 3 digits after decimal. I mean both of them should work in one space. I wrote a line of code, it works but when there is "0" digits after decimal, it shows only numbers that except the "0"
here is my code and output:
print("%-15s %-15s %-15s %-15s %s" %(sp_id_516,list(utp_516.items())[i-1][0], round(next_azimuth_516,4),round(list(utp_516.items())[i-1][1][2],2),round(list(utp_516.items())[i-1][1][3],2)))
For example, there should be one more digits. I want to show 3 digits after decimal whatever digits are
Upvotes: 0
Views: 362
Reputation: 3115
Instead of using the string representation (%s
) you can use the floating-point notation (%f
). Docs
>>> print("%-15s %-15s %-15.3f %-15.3f" % ("A", "B", 12.13465, 123.1000))
A B 12.135 123.100
Upvotes: 1