-2

If i do the normal calculation means its working, but if i pass the value from form means its not working kindly please help me.

For example:

echo $a=(1.5 * 10E-8) - (4.6 * 10E-8); 

Result : -3.1E-7 but its not working when I get the values from form.

For example:

echo $m3=($_REQUEST['m3']); echo "<br>"; \* m3 value getting from form */
echo $m2=($_REQUEST['m2']); echo "<br>"; \* m2 value getting from form */
echo $b=$m3-$m2; 

Result : -3.1

I need the result fully with that scientific notation.

zzlalani
  • 22,960
  • 16
  • 44
  • 73
user3048458
  • 7
  • 2
  • 4

3 Answers3

1

You need to cast the form's post values into float

echo $m3=(float)($_REQUEST['m3']); echo "<br>"; \* m3 value getting from form */
echo $m2=(float)($_REQUEST['m2']); echo "<br>"; \* m2 value getting from form */
echo $b=$m3-$m2; 
zzlalani
  • 22,960
  • 16
  • 44
  • 73
0

Form working properly. You just need to always echo your result in scientific notation and remove * from form inputs:

$a = '1.510E-8';
$b = '4.610E-8';
echo sprintf('%e', $a-$b);
//result: -3.100000e-8
V G
  • 1,225
  • 9
  • 13
0

Form values return strings or arrays of strings. You need to cast them into an numeric type, if you would like to do calculations with them..

For example:

$m3 = intval($_REQUEST["m3"]);
nl-x
  • 11,762
  • 7
  • 33
  • 61