-1

While performing arithmetic operations on arrays, and the output is an integer why does the output display 1. or 11. instead of 1.0 or 11.0? Is there a way to display the integer with the floating-point value such as instead of 1. or 11. as 1.0 or 11.0?

1
  • 1
    Maybe you can int(...) the result Commented Aug 16, 2021 at 8:35

2 Answers 2

1

In Python, you can format floating numbers to a specific decimal places like this:

pi = 3.1415926
formatter = "{0:.2f}"
output = formatter.format(pi)  # 3.14

You can read more about this here: https://mkaz.blog/code/python-string-format-cookbook/

Sign up to request clarification or add additional context in comments.

Comments

1

Convert it to float

my_list = [1,2,3,4,5,6]
for element in my_list:
    print( float(element) )

you will get the "1.0" "2.0" and e.t.c

You can do it on any integer

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.