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?
            Asked
            
        
        
            Active
            
        
            Viewed 178 times
        
    -1
            
            
        - 
                    1Maybe you can `int(...)` the result – Contestosis Aug 16 '21 at 08:35
2 Answers
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/
 
    
    
        danyroza
        
- 154
- 1
- 10
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
 
    
    
        Elguja Lomsadze
        
- 118
- 2
