|
Posted by Jackson Scott Peebles on 05/28/06 18:23
Hey everyone! I'm a complete newbie to PHP, and am trying to teach
myself how to make some scripts. So far I've done pretty good, but
even after searching through all my books, articles, manuals, and
search engines on PHP, I can't figure out how to stop PHP from
rounding. I am trying to create a calculator that calculates a
diameter * pi, and I got it, but I can't stop it from rounding to a few
digits, which is very annoying. I'm looking at calculating like ten
thousand digits and printing all of them (I know this doesn't sound
convenient, but it will not be used for public use, just for some
clients of mine that say they want accuracy). So far my calculator
looks like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>
<title>Pi Calculator</title>
</head>
<?php
include("variables.php");
?>
<body>
<form action="" method="post">
<input name="diameter" type="text" size="10" maxlength="500" />
<select name="method1">
<option value="add" selected="selected">+</option>
<option value="sub">-</option>
<option value="multi">*</option>
<option value="div">/</option>
</select>
<input name="submit1" type="submit" value="Submit" />
<input name="reset1" type="reset" value="Reset" />
</form>
<?php
// Get variables from POST:
$submit1 = $_POST['submit1'];
$submit2 = $_POST['submit2'];
$method1 = $_POST['method1'];
$method2 = $_POST['method2'];
$diameter = $_POST['diameter'];
$second = $_POST['second'];
$number = $_POST['number'];
// Simple
if ($submit1 == true) {
switch ($method1) {
case add: $ans = $first + $second;
break;
case sub: $ans = $first - $second;
break;
case multi: $ans = $diameter * $pi;
break;
case div: $ans = $first / $second;
break;
}
$ans = number_format($ans, 500, '.', ',');
echo "<p>$ans</p>";
}
?>
</body>
</html>
I know it isn't finished yet and that there is a lot of unneeded code,
but I will fix that once I stop it from rounding. variables.php just
has pi in it. If you can help me out I'd really appreciate it!
Navigation:
[Reply to this message]
|