hockeyman
hockeyman

Reputation: 1183

PHP maths rounds values

In my database I have many columns of type: VARCHAR Some of them contains numbers like lets say: 12,25. And now I have a situation when I have to SUM these columns. Lets say it looks like that:

[-COL1--COL2--COL3-]
[-12,5--0,00--0,00-]

So the SUM of COL1+COL2+COL3 should be 12.5, but it gives me 12 only. If I print each column seperate without summing it it shows good value. Whats the problem?

Upvotes: 0

Views: 39

Answers (1)

gbestard
gbestard

Reputation: 1177

The problem is that you have 12,5 instead of 12.5 Try to change it with this:

$number = '12,5';
$number = str_replace(',', '.', $number);

and then add it up

Upvotes: 1

Related Questions