Modulus (%) operator behave awkwardly!

This is where you share YOUR scripts with others

Moderators: egami, macek, gesf

Post Reply
seandisanti
php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Mon Mar 04, 2013 1:01 pm

The reason this happens is a little more complicated than i currently have time to explain, but if you explicitly round it though, it works.

Code: Select all


<?php
$val = .815;
$val = round($val * 10000); // $val should be 8150
echo $val . '<br />';
$a = $val % 50; // $a should be 0
echo 'remainder: '. $a ;

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest