PHP returns incorrect total

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Post Reply
MeroD
New php-forum User
New php-forum User
Posts: 53
Joined: Wed Oct 10, 2012 12:14 am

Re: PHP returns incorrect total

Post by MeroD » Wed Nov 07, 2012 10:51 pm

Floating-point data types like DOUBLE are approximate and do not represent exact numbers.

number_format($...total) may give you better results.

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: PHP returns incorrect total

Post by johnj » Thu Nov 08, 2012 8:23 am

It is better to use the bcmath function for math calculations.
http://php.net/manual/en/book.bc.php

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 7 guests