![]() |
$n * 1000 and Mod
I've been using fmod to validate data entry in Terry's Turkeys. You need to check weights are entered in 5g increments. So i take the input, *1000 and take the modulus for 5.
This threw up an odd bug when i inputted 8.065kg. Perfectly valid, as you can see. But rejected by my code. So i did a test: :
for ($n = 0; $n < 10; $n += 0.005)You'll find the output rather odd: Results Why's it doing this? It's not just fmod() being weird as it's for floating points, but % too. |
Hope you get this working, mate.
Oh, and could you put borders on that table? It's hard to read. EDIT: Got it: :
$n = round($n, 5); |
Yeah, the trouble is that although it's an integer, it's an integer stored in a floating point variable and you can't use modulo with floating point, even if it happens to contain an integer value.
|
| All times are GMT -5. The time now is 3:53 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC