[thelist] PHP type and value match, but value comparssion fails.

Liam Delahunty liam at megaproducts.co.uk
Wed Aug 25 09:03:03 CDT 2004


on 25/08/2004 14:33 Richard Davey said the following:

> On Wed, 25 Aug 2004 14:03:29 +0100, Liam Delahunty
>>Just for error checking I want to check that the total price is equal to
>>the unit_price * sold_by. However, I've noticed that some prices,
>>despite being 'the same', always error!
>>
>>eg,
>>  3 units X 0.5 = 1.5, works
>>  3 units X 0.6 = 1.8, fails...
>>
>>So, what gives? How can I check these values, and what is causing the
>>errors?
> 
> 
> How are you actually comparing the values? Are you sure they are not
> being rounded in some way? (i.e. 1.8 rounding to 2.0 or similar). Post
> that piece of the code perhaps?

In the form [1], which is the more important thing, the 
calculation/comparison is just a very simple

if ($price != $mysum){
	//	error stuff
}

Where price is the input field, and mysum is the programs calculation of 
unit_price * sold_by.

The code is here:
http://www.liamdelahunty.com/tips/weird/math_on_string_form.txt

the other (box) page is just me mucking around really to see if there 
were any obvious patterns, but I can't see it, other than X 3 and X 6 
being identically bad. and x7 and x9 sort of complimenting each other a 
bit... sometimes... Hmmmmm....

1. http://www.liamdelahunty.com/tips/weird/math_on_string_form.php


-- 
Kind regards, Liam Delahunty, Mega Products Ltd
12 Bury Place, London WC1A 2JL Fax: +44(0)871 224 7891
http://www.megaproducts.co.uk/ Internet Design & Development


More information about the thelist mailing list