Skip to content Skip to sidebar Skip to footer

How Do I Change The Format/amount Of Digits That Appear?

I'm very new to Python and have a question. Currently I'm using this to calculate the times between a message goes out and the message comes in. The resulting starting time, time d

Solution 1:

If float(out_ts) are hours, then '{0:.3f}'.format(float(out_ts) * 3600.) will give you the text representation of seconds with three digits after decimal point.

Solution 2:

How can I force it to always display the exact number.

This is sometimes not possible, because of floating point inaccuracies

What you can do on the other hand is to format your floats as you wish. See here for instructions.

E.G: replace your yield line with:

yield ("%.5f"%float(out_ts),"%.5f"%ref_id[1:-1], "%.5f"%(float(in_ts) - float(out_ts)))

to truncate all your values to 5 digits after the comma. There are other formatting options, for a lot of different formats.

Post a Comment for "How Do I Change The Format/amount Of Digits That Appear?"