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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

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

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

Experts Exchange Solution brought to you by

Your issues matter to us.

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

Start your 7-day free trial
Ivo StoykovCommented:
Hello PeterErhard,

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

HTH

I
Ivo StoykovCommented:
Hi PeterErhard,

sorry misunderstood the question

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

regards

I
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

KennyTMCommented:
Just to make the situation clearer...

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

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 :)
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.