2

Why in PHP language, the code below prints 7 ?

print (int) ((0.1+0.7) * 10)

While

print (int) ((0.1+0.8) * 10)

prints 9 ?

  • Because a `int` conversion just strips the decimals and floating point math isn't precise. You could use `round` instead – Philipp Jul 09 '18 at 09:04

1 Answers1

0

You need to use round() function while converting float values

print (int) round((0.1+0.7) * 10);
Siddhartha esunuri
  • 1,104
  • 1
  • 17
  • 29