Changing Bytes to KB, to megs, to gigs.

From: Date: Sat, 26 Jul 2003 22:00:07 +0000
Subject: Changing Bytes to KB, to megs, to gigs.
Groups: php.general 
Request: Send a blank email to php-general+get-157034@lists.php.net to get a copy of this message
My goal is to input the amount of Bytes used by a user as $inputbox and calculate how many kbs,megs,gigs along with $cost for the price per meg. <? $inputbox = "414478244"; // PROCESS DATA $kbs = $inputbox/1024; $megs = $kbs/1024; $gigs = $megs/1024; // CALC COST OF MEGS cost = $megs * 0.05; // OUT PUT DATA. echo"<b>$inputbox bytes = </b><br>$kbs kb.<br>$megs meg @ $0.05c per Meg = \$$cost<br>$gigs gig.<br><br>"; ?> This is what I get outputted. 414478244 bytes = 404763.910156 kb. 395.277256012 meg @ $0.05c per Meg = $19.7638628006 0.386012945324 gig. Questions? 1. Should I be dividing by 1024 or 1000? This was passed to me by word of mouth ... 2. Any way of rounding to 2 or 3 digests after the decimal point. 3. to remove any , from the inputted string. / Josh

« previous php.general (#157034) next »