0

how to make output 22//7 on python 2.7 become 3.14159 ?i try use float(22/7) but it just give me 3.0. I try use Decimal but it just give me 3, use round(x, 6) only give 3.0 just like float.

Elonelon
  • 68
  • 1
  • 12

1 Answers1

1

Here, int/int will return int only that is what happening here 22/7 gives 3 and you're type casting it to float(3) which is giving 3.0 but if you will perform float/int or int/float then it will result into float so you convert any of them to float as shown following.

replace float(22/7) with float(22)/7

Mahesh Karia
  • 2,045
  • 1
  • 12
  • 23