0
python int to float
check the attached code. why it shows lengthy output while give an integer in place of float for example, input: 2,456 output: 182.85000000000002 expected: 182.85 https://code.sololearn.com/cXrAUDYfAtAQ/?ref=app
6 Respuestas
+ 1
Amal Benny, This is because of how floating point numbers are represented in almost every programming languages.
https://docs.python.org/3/tutorial/floatingpoint.html
+ 1
Use: round(your_float, 2) so it will be float with 2 digits after a dot.
0
Did you correct it? cuz i'm not seeing anything like that.
0
No, there is no change after the posting of discussion. Please try the example given in a good python interpreter.
for prefilled one check : https://ideone.com/cELp7M
0
Amal Benny By default Python don't stop at double-precision after the 2 digits.
sol-
print("{:.2f}".format(dc_frk))