0

I want to know how many decimals an input has to then use that information to aproximate the result of an operation to the same number of decimals. For example:

example = float(input('n '))

Imagine the input is 1.99, how do I obtain the number of decimals (2) to then use it?

  • If the user types “3.100”, do you want to use three digits after the decimal point? Read the input as a string and count the digits after the decimal point before converting it to floating-point. – Eric Postpischil Dec 19 '20 at 12:24

1 Answers1

0

Here's a simple hack to it.

dec = len(str(example).split('.')[1])
shekhar chander
  • 600
  • 8
  • 14