Back

Explore Courses Blog Tutorials Interview Questions
0 votes
4 views
in Python by (47.6k points)

How do I get 1324343032.324?

As you can see below, the following do not work:

>>1324343032.324325235 * 1000 / 1000 

1324343032.3243253 

>>int(1324343032.324325235 * 1000) / 1000.0 

1324343032.3239999 

>>round(int(1324343032.324325235 * 1000) / 1000.0,3) 1324343032.3239999 

>>str(1324343032.3239999) 

'1324343032.32'

1 Answer

0 votes
by (106k points)

To truncate to three decimals in Python you can use the below-mentioned code:-

'%.3f'%(1324343032.324325235)

Use an additional float() around it if you want to preserve it as a float.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Dec 10, 2020 in Python by laddulakshana (16.4k points)
0 votes
1 answer
asked Oct 11, 2019 in Python by Sammy (47.6k points)
0 votes
4 answers
asked Apr 6, 2021 in Python by laddulakshana (16.4k points)
0 votes
4 answers

Browse Categories

...