negative zero

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

raphael75
New php-forum User
New php-forum User
Posts: 20
Joined: Fri Apr 06, 2012 9:54 pm

negative zero

Postby raphael75 » Thu May 01, 2014 10:14 am

So I have 2 arrays of numbers, and this:

$variance = array_sum($db_tot) - array_sum($cr_tot);

If the sum of each array is the same, why does PHP return -1.8189894035459E-12? Why wouldn't it be 0 (positive 0 or just 0)?

Thanks!

raphael75
New php-forum User
New php-forum User
Posts: 20
Joined: Fri Apr 06, 2012 9:54 pm

Re: negative zero

Postby raphael75 » Thu May 01, 2014 10:26 am

Figured it out - floating point math isn't straightforward. Had to use number_format to round to 2 decimal places.


Return to “PHP coding => General”

Who is online

Users browsing this forum: Google [Bot] and 2 guests

cron