How to convert float to string with N digits precision in Python

2 Answers

0 votes
float = 7.56983

s = f'{float:.2f}'

print(s)  






'''
run:
 
7.57
 
'''

 



answered Jul 15, 2022 by avibootz
0 votes
float = 7.56983

N = 2

s = str(round(float, N))

print(s)  






'''
run:
 
7.57
 
'''

 



answered Jul 15, 2022 by avibootz

Related questions

...