+ 3
Why not Accurate???
in python, many calculations are not accurate. Why is so? For example: https://code.sololearn.com/cv5pz1sy3grG/
5 Answers
+ 8
Floating-point numbers are represented in computer hardware as base 2 (binary) fractions. https://docs.python.org/3/tutorial/floatingpoint.html
+ 8
Fore more accuracy, use the decimal module.
from decimal import Decimal, getcontext
getcontext().prec = 5
print(Decimal(3.3) * Decimal(3)) # 9.9000
+ 1
3ļ½Ķ£ļ½ļ½ĶŖļ½Ķ£ļ¼æĶ„
Line 10 where you get the input, convert to float:
i = float(input(''))
Line 28 to print, you can specify precision with string formatting too:
print(f'{i} x {n} = {i*n:.5f}')
0
Ok that is a solution, but why does it shows slight difference?
0
https://code.sololearn.com/crr3SPxPeW2g/
For example if i program to make a table of some input.... input could be floating or int number...... what should be ammended there?