Calculation

I'm getting a result with a sum of a database column of 21.8

What I then want to be able to do is once I've written the value to a variable is to:

21 (number before the bullet point) x 6 = 126
126 + 8 (number after the bullet point) = 134.... write 134 to another variable
PeterErhardAsked:
Who is Participating?
 
KennyTMCommented:
Suppose $x == "21.8" (the string).
Then,

$a=explode('.', $x);
echo $a[0]*6+$a[1];
0
 
Ivo StoykovCommented:
Hello PeterErhard,

$db_var = (int)21.8 * 6;
or
$another_var = (int)21.8 * 6 + 8;

HTH

I
0
 
Ivo StoykovCommented:
Hi PeterErhard,

sorry misunderstood the question

$a = (int)21.8 * 6 + 21.8 % (int)21.8;

regards

I
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
KennyTMCommented:
Just to make the situation clearer...

What will you expect to output when the number is, e.g., 12.345 ?
0
 
waygoodCommented:
yes you did ivostoykov! since you've just done  
$a = 21 * 6 + 0.8;   // using 0.8 not 8

I suspect KennyTM was right first time.

What happens with trailing 0's, the answer for 1.2 would differ to 1.20

0
 
PeterErhardAuthor Commented:
Thanks guys, and yes Kenny was correct the first time. The way the data is being returned and read makes it impossible for there to be two decimal places but thanks for the consideration Waygood, appreciate it :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.