1

I want to define the precision of a float while taking it as an input

NGAS=float(input("enter a number with 3 decimal places"))

instead of mentioning the 3 decimal places I want to do the equivalent of

print('%.3f%' % ESTART)

while taking the input. Since, it affects my calculations.

3
  • 2
    Changing the print representation of a float won't impact your calculations. float is float, you don't get "3 decimal place floats". If you need to do decimal maths, you may need to use decimal module. This may be an XY problem. Commented Jun 8, 2018 at 11:20
  • @jpp What is an XY problem? Commented Jun 8, 2018 at 11:22
  • XY problem Commented Jun 8, 2018 at 11:23

1 Answer 1

1

You can round the inputted number:

ngas = round(float(input("enter a number: ")), 3)
Sign up to request clarification or add additional context in comments.

1 Comment

While this answers OP's question, it doesn't address the potentially error-prone Since, it affects my calculations part. Your rounded float is still a float.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.