Greg J
Greg J

Reputation: 15

How to round to a certain amount of decimals while leaving a 0

see the list below:

2456905.204109
2456905.204132
2456905.204144
2456905.204155
2456905.204167
2456905.204178
2456905.20419
2456905.204201
2456905.204213
2456905.204225

The list goes on. I want to have the list all lined up so I want a 0 to the left of 2456905.204109.

I am just using x = round(num,6), but is there a way to always have 6 decimals? I haven't found anything other than other ways to round, which result in the same thing.

Upvotes: 1

Views: 76

Answers (2)

Akshay
Akshay

Reputation: 812

The number itself will not contain any insignificant digits as mentioned above, but you can alter the formatting when you print it. For instance you could write:

>>> x = round(2456905.20419, 6)
>>> '%0.6f' % x

Which will display as:

'2456905.204190'

Contrast this to just printing x without formatting, which will display as you are seeing right now:

2456905.20419

Upvotes: 0

IceArdor
IceArdor

Reputation: 2041

Use string formatting

>>> '%0.6f' % 2456905.20410897654321
'2456905.204109'
>>> '%0.6f' % 2456905.20419
'2456905.204190'

Upvotes: 2

Related Questions