homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Textbox comparison on a webserver running on a Ethernet

 7:57 pm on Oct 8, 2012 (gmt 0)

Hi there People,

I've got a math probelm, and I can't fathom it out; Id be greatful if I could bounce it here to see if there is anyone who can shed light on this issue.

I have two textbox's that get populated via ethernet to development PCB, and read voltages that are scaled to 250.00V (32767 (16BIT)), and the other textbox is the requested value ie 125.00V (16383 scaled).

As this is a website driven PCB - from webserver, I would like to know how I can present the maths so that I can detect when the read value is +/- 1% of request.

To be honest it's just the maths side of this I can't fathom.

I'd appreciate any ideas,




 11:21 pm on Oct 8, 2012 (gmt 0)

do you need the formula to calculate the percentage?
it's the difference between read and requested divided by requested.
multiply that by 100 to get percentage.
use an absolute value function too capture +/-.
compare the result to 1.0


 6:28 pm on Oct 9, 2012 (gmt 0)

Hi there Phranque,

Thanks for the idea, sounds promising; I'm not brilliant at maths, so it's nice to get another perspective/set of thoughts on this.

I'll be having a play with this before the end of the week, so I'll post back and let you know how I've got on.

*Pseudo code*

CapturedReading = (((ReadValue - SetPoint) / Setpoint) * 1.0)

Putting the margin of error there I think is wrong.. but I've got code here that looks similar to this that I use the work out the scaling including the margin of error

CapturedResult = (CapturedReading * 100)

Somthing like that would be comparing the the result to the 1% margin of error wouldn't it?

Feeling a bit daft now really, somthing this simple, and it's cost me more time than calculating 16bit CRC's!

Thanks for the advice!



 8:27 pm on Oct 9, 2012 (gmt 0)

expected value: X

1%: 1*X/100

bottom: X - X/100 = 99X/100
top: X + X/100 = 101X/100

Read value: Y
if 99X/100 <= Y and Y<= 101X/100 then it's within 1% of X

To speed things up: forget about dividing by 100 (division is slow compared to multiplication):

if ( ( 99*X <= 100*Y) and (100*Y <= 101*X) ) then Y is within 1% of X


 7:37 pm on Oct 12, 2012 (gmt 0)


Cool, thanks for this. I appreicate your input :)


PS: I'll test this on Monday & report back

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved