Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

little help with PHP program


ghost's Avatar
0 0

well I'm trying to make a kind of memory converter (B=>MG=>GB=>TB….)

either Im doing my math wrong or php doesnt like big numbers, can someone tell me if im on the right track or if im doing something wrong?

this is what i have so far i quit when i started getting weird numbers

<h1>Megabyte converter</h1>

<form action=test.php method=post>
Bytes: <input type=text name=b></br>
Kilobytes: <input type=text name=k></br>
Megabytes: <input type=text name=m></br>
Gigabytes: <input type=text name=g></br>
Terabytes: <input type=text name=t></br>
Petabytes: <input type=text name=p></br>
Exabytes: <input type=text name=e></br>
Zettabytes: <input type=text name=z></br>
Yottabytes: <input type=text name=y></br>
<input type=submit value=calculate></br>
</form>


<?php

	$b = (int)($_POST ["b"]);
	$k = (int)($_POST ["k"]);
	$m = (int)($_POST ["m"]);
	$g = (int)($_POST ["g"]);
	$t = (int)($_POST ["t"]);
	$p = (int)($_POST ["p"]);
	$e = (int)($_POST ["e"]);
	$z = (int)($_POST ["z"]);
	$y = (int)($_POST ["y"]);
	 
	
	echo  ("Bytes: " . $b . '</br>' );
	echo  ("Kilobytes: " . $b /1024  . '</br>' );
	echo  ("Megabytes: " . $b /1048576 . '</br>' );
	echo  ("Gigabytes: " . $b /1073741824 . '</br>' );
	echo  ("Terabytes: " . $b /1099511627776 . '</br>' );
	echo  "Petabytes: "
	echo  "Exabytes: "
	echo  "Zettabytes: "
	echo  "Yottabytes: "
	
?>

ps im new to php so dont flame me


ghost's Avatar
0 0

wait I just read something on bcdiv()

soo… let me test


ghost's Avatar
0 0

Does any of it work?

Do small-scale calculations output correctly??


ghost's Avatar
0 0

yea small numbers work but if you but a big number in it goes all weird

I put in 1099511627776 in bytes text field to test the terabyte so according to the script it should have echoed out 1

because 1099511627776 /1099511627776 = 1 duh!

but it gives me all these numbers


ghost's Avatar
0 0

My freaking brain is killing me I don't know what I'm doing wrong.


ghost's Avatar
0 0

never mind just figured it out :@:@


ghost's Avatar
0 0

Sorry, I had to go to work, lol. Good job ;)