[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
Solved

# Calculation

Posted on 2006-04-20
Medium Priority
178 Views
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
0
Question by:PeterErhard

LVL 8

Accepted Solution

KennyTM earned 2000 total points
ID: 16495666
Suppose \$x == "21.8" (the string).
Then,

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

LVL 22

Expert Comment

ID: 16495682
Hello PeterErhard,

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

HTH

I
0

LVL 22

Expert Comment

ID: 16495695
Hi PeterErhard,

sorry misunderstood the question

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

regards

I
0

LVL 8

Expert Comment

ID: 16495720
Just to make the situation clearer...

What will you expect to output when the number is, e.g., 12.345 ?
0

LVL 9

Expert Comment

ID: 16496467
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

Author Comment

ID: 16496507
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

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
###### Suggested Courses
Course of the Month20 days, 4 hours left to enroll