Stop PHP from rounding



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!
.



Relevant Pages

  • Stop PHP 5 from Rounding
    ... I'm a complete newbie to PHP, ... diameter * pi, and I got it, but I can't stop it from rounding to a few ... digits, which is very annoying. ... So far my calculator ...
    (comp.lang.php)
  • Re: how do I get more numbers past the decimal?
    ... Jake Barnes schrob: ... I'm worried that PHP is rounding these numbers off. ... Die Liebe zur Schule wächst mit dem Quadrat der Entfernung! ...
    (comp.lang.php)
  • Re: how do I get more numbers past the decimal?
    ... I'm worried that PHP is rounding these numbers off. ... significant digits of precision is *insufficient* ?? ...
    (comp.lang.php)
  • Re: XQ and ->Qpi bug on large X
    ... did away with the IEEE directed rounding that the HP71 had ... What if the calculator were used for finance ... OTOH: VBScript's Round vs. FormatNumber and Format$: ... stored with 12 total digits is irrelevant. ...
    (comp.sys.hp48)
  • Re: XQ and ->Qpi bug on large X
    ... I don't advocate rounding when you don't have to. ... for a lesser number of mantissa digits than the calculator supports ... Are you saying that since the calculator supports some number of mantissa ... can lead to bias, the "round to even" method being capable, ...
    (comp.sys.hp48)