emd,
@emd@cosocial.ca avatar

Anyone out there in #php or #laravel -land explain this?

ethernick,
emd,
@emd@cosocial.ca avatar

@ethernick sure but why is 220/2.2 == 100.0 and the intval of that 99?

perfect5th,

@emd @ethernick if I had to guess, 2.2 stored as a float has some error making it slightly greater than 2.2. Division makes the answer slightly less than 100.0, and intval lops off the IEEE 754 remainder.

Straight division follows saner rounding rules than intval when representing the value as a string.

emd,
@emd@cosocial.ca avatar

@perfect5th @ethernick but how does the intval change it. So confused.

ramsey,
@ramsey@phpc.social avatar

@emd @perfect5th @ethernick The real value of 220/2.2 might be something like 99.99999999999999, when dealing with floating point numbers, and that’s very different from your hard-coded 100.0.

intval(100.0) == 100
intval(99.99999999999999) == 99

ramsey,
@ramsey@phpc.social avatar

@emd @perfect5th @ethernick The Floating-point Guide is required reading for all software engineers. 🙂

https://floating-point-gui.de

emd,
@emd@cosocial.ca avatar

@ramsey @perfect5th @ethernick sure but the 220/2.2 shows 100.2. That’s what i don’t get.

ramsey,
@ramsey@phpc.social avatar

@emd @perfect5th @ethernick In your screenshot, 220/2.2 appears to show 100.0, not 100.2. Am I missing something?

What version of PHP are you using? It looks like there’s a big difference between how this works between 7.4 and 8.

https://3v4l.org/fhh8l#v7.4.33

  • All
  • Subscribed
  • Moderated
  • Favorites
  • php
  • DreamBathrooms
  • magazineikmin
  • tacticalgear
  • cisconetworking
  • ethstaker
  • rosin
  • love
  • Youngstown
  • slotface
  • khanakhh
  • kavyap
  • osvaldo12
  • thenastyranch
  • everett
  • provamag3
  • InstantRegret
  • tester
  • normalnudes
  • ngwrru68w68
  • cubers
  • GTA5RPClips
  • mdbf
  • Durango
  • anitta
  • modclub
  • Leos
  • megavids
  • JUstTest
  • All magazines