How can I check that?
How can I check if a number is approximately equal to the other? I've been searching for 2 days and I didn't find any post that could help me, so either i'm blind or there aren't much topics about that.
I thought about (Z - Y) < 5 but I don't think it's the best way to do that... maybe. |
Re: How can I check that?
Unless I misunderstand what you mean by "approximately equal", then (Z - Y) < 5 is exactly what you should be doing.
|
Re: How can I check that?
Quote:
Someone correct me if I'm wrong but, PHP Code:
|
Re: How can I check that?
Seems that my first idea was correct then, but I think I should make something more "universal". Like: If X value is 90% of the Y value is better, isn't it?
Let's suppose that we have 100 as X and 95 as Y, then we've 95% of the main value, so it's kinda approximated, or is it the same idea as doing X - Y < 5? |
Re: How can I check that?
Quote:
|
Re: How can I check that?
What do you mean with the same ? Closer to each other?
Are you using floats ? Then use floatround.. Can you explain what are you doing this for? Also pick out a better title for your thing. Edit : best thing is to use your first thing no need to overcomplicate a simple thing |
Re: How can I check that?
How about this?
This will check if iValueToCheck is >= fVariance percent of iCompareToValue. PHP Code:
Code:
Is 95 >= 90% of 100? = Yes |
Re: How can I check that?
Quote:
v 76 15 30 NE 60 75 E 105 120 SE So, I asked that because if i'm looking at the direction 76, the next ones will be 91, 106, 121, etc... so with the approximate value, I could change the 91 or 106 to 90 and 105, y'know? Quote:
Edit: Worked, thank you guys, specially Bugsy. |
Re: How can I check that?
In that case you just should align your current angle to an increment of 15.
Code:
new const alignedAngle = (floatround(currentAngle + 7.5) / 15) * 15; And please set a proper title. |
Re: How can I check that?
I'm not bumping, since I already solved it, I'm just answering KliPPy's reply:
That's what I'm doing: PHP Code:
floatround(175.0 + 7.5) = 182.0 182.0 / 15 = 12.13 12.13 * 15 = 182.0 ?? Did I misunderstand it? |
All times are GMT -4. The time now is 04:18. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.