# 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
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
Suppose \$x == "21.8" (the string).
Then,

\$a=explode('.', \$x);
echo \$a[0]*6+\$a[1];

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
Hello PeterErhard,

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

HTH

I
Commented:
Hi PeterErhard,

sorry misunderstood the question

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

regards

I
Commented:
Just to make the situation clearer...

What will you expect to output when the number is, e.g., 12.345 ?
Commented:
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

Author 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 :)
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.