user2515736
user2515736

Reputation: 3

SQL Float value not = 0

I have a problem with some SQL value & PHP. I am doing 2 request, one to add a value into my sql and the other one to minus this result.

Here it is :

$totaux = $montant_actuel + ($nbre_dej * $prix_dejeuner) + ($nbre_din * $prix_diner) + ($nbre_soir_etape * $prix_etape);

When i'm doing this, it's equal to:

sum = 0 + (15.8*1) + (15.8*1) + (57.8*0)

So I have : 31.6

But when i'm trying to do :

$totaux = $montant_actuel - ($nbre_dej * $prix_dejeuner) - ($nbre_din * $prix_diner) - ($nbre_soir_etape * $prix_etape);

sum = 31.6 - (15.8*1) - (15.8*1) - (57.8*0)

And then, when i insert it into my DB i have this record : 0.0000000000000142109 instead of 0

I don't understand why is this happening.

Upvotes: 0

Views: 809

Answers (2)

Cracker0dks
Cracker0dks

Reputation: 2490

It can be a problem with precision of numbers... use some functions from: here

Upvotes: 0

Andreas Linden
Andreas Linden

Reputation: 12721

it seems like a simple rounding error inside the database. if you're using float or double change it to decimal to avoid rounding errors.

Upvotes: 1

Related Questions