0

I want to aproximate my result of an operation to the same amount of decimals of my input number.

inclined_plane_f = float(input('F '))
inclined_plane_r = float(input('R '))
inclined_plane_h = float(input('h '))
inclined_plane_l = float(input('L '))
check = cmath.sqrt(inclined_plane_l ** 2 - inclined_plane_h ** 2)
if inclined_plane_l == cmath.sqrt(check ** 2 + inclined_plane_h ** 2):
    pass
else:
    raw_inclined_plane_l = cmath.sqrt(check ** 2 + inclined_plane_h ** 2)
    dec = len(str(inclined_plane_l).split('.')[1])

I want to make raw_inclined_plane_l to have the same amout of decimals as inclined_plane_l (the input) aproximating it to check if the number of the input was correct.

1 Answers1

0

Get the number of digits after the decimal before converting the input to float.

inclined_plane_str = input('L ')
dec = len(inclined_plane_str.split('.')[1])
inclined_plan_l = float(inclined_plan_str)
Barmar
  • 741,623
  • 53
  • 500
  • 612