negative zero

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

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

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: 32
Joined: Fri Apr 06, 2012 9:54 pm

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.

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 3 guests