-5

Perhaps I am incredibly stupid, but I have no idea why the output is negative?

It is really affecting my program

<?php

$vone =  10833087074.438;


$massone = 1;
$keone = $vone ^ 2;

echo $keone;
echo "<BR>";
$keone = $keone * $massone;
echo $keone;
echo "<BR>";
$keone = .5 * $keone;

echo $keone;

?>
Orca
  • 73
  • 1
  • 8

2 Answers2

2

Many notations use "^" as a power operator, but in PHP (and other C-based languages) that is actually the XOR operator. You need to use this 'pow' function, there is no power operator.

In your code

$keone = $vone ^ 2;

Should be

$keone = pow($vone,2);

Rest of your code is fine. That pow function is the one you should use to raise your baise to the power given.

Hanky Panky
  • 44,997
  • 8
  • 67
  • 93
0

Use this code

<?php

$vone =  10833087074.438;


$massone = 1;
$keone = pow($vone,2);

echo $keone;
echo "<BR>";
$keone = $keone * $massone;
echo $keone;
echo "<BR>";
$keone = .5 * $keone;

echo $keone;

?>
akhilesh
  • 54
  • 5