sum amount using php help

i sum amount in this value but i not know how

for example

$sum1 = “0.040”;
$sum2 = “23”;
$sum3 = “30”;

$sum4 = $sum2+$sum3;

$sum5 = sum4*20;

$sum6 = $sum1+$sum5;

echo $sum6;

result show
1060.04

but i show result this how can

0.05060

0.040 + ((23+30)*20) = 1060,04

Did you want 0.05060? If so you math is wrong

Did you get 0.0.5060? If so something isn’t right here, I tried running this on PHP 4 - PHP 7 and all returned 1060,04
Perhaps it’s the sum4 that is an undefined constant, if you’ve turned off all errors that might give you some issues.

What are you trying to do? The way you are going about you answer obviously isn’t the route to go, but I don’t know what you are trying to do, or why you are trying to do it.

[php]$sum1 = “0.040”;
$sum2 = “23”;
$sum3 = “30”;

$sum4 = $sum2+$sum3;
53

$sum5 = $sum4*20;
1060

$sum6 = $sum1+$sum5;
1060.04[/php]

my math is not wrong please sir read again this question i asked this question that
result show me
1060.04
i know when i sum this values sum show me this
but i want to sum this type
0.05060
how can do type the code or how can change decimal value and then sum
that my question

different style learn what i asked
$sum2 = “23”;
$sum3 = “30”;
$sum4 = $sum2+$sum3;
$sum5 = $sum4*20;

result show is
1060
i change it into decimal format
0.01060
then sum into
$sum1
and get rewult
0.05060
how can do this in php

Forget about programming, that isn’t how math works period. 2+2 will always be 4 regardless of how you do it.

1 Like

Perhaps some BEDMAS would get the desired result? I’m not going to play around with the numbers but maybe you will find a combination that will work.

P.S: It is not really clear what you are asking. Perhaps you can re-phrase your question for better assistance.

…Frank

Is it me or should the numbers not be enclosed in double quotes I get 1060.04

$sum1 = 0.040;
$sum2 = 23;
$sum3 = 30;

$sum4 = $sum2+$sum3;

$sum5 = $sum4*20;
echo $sum6 = $sum1+$sum5;

I personally do not quote numbers but PHP is a loosely typed language so what he is doing is valid… Maybe not the best form but valid.

Change the formula below to get 0.0506

This is what you wrote:
0.040 + ((23+30)*20) = 1060,04

This is what you want:
?

<?php $sum1 = 0.040; $sum2 = 23; $sum3 = 30; $sum4 = $sum2+$sum3; $sum5 = $sum4*20; echo ($sum5/100000)+$sum1; ?>
Sponsor our Newsletter | Privacy Policy | Terms of Service