2 floating numbers substract in a query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

2 floating numbers substract in a query

Post by pelegk2 »

have this query :

Code: Select all

SELECT costumers.id as cID,sum(users_payment .total_bill-actuall_payed) 
from costumers 
LEFT JOIN users_payment ON users_payment.userid=costumers.id  AND users_payment.month<5 
group by cID 
LIMIT 0, 50


in the first result i get instead of 92 i get : 91.199996948242
what can i do to prevent this? and get the correct answer?
by the way in the first line i am adding 2 number : 45.5 and 46.5=92
so whats the solution
tnaks in advance
peleg
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Well, you could use abs(sum(users_payment.total_bill-actuall_payed)) or similiar if you need to strip of the decimals, but there is also CEIL() and FLOOR() depending on preference (discounts, goodwill aso aso).

Browse the math functions that mysql uses and you might find something that fits you better.
Post Reply