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

x
?
Solved

Calculation

Posted on 2006-04-20
6
Medium Priority
?
178 Views
Last Modified: 2008-03-06
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
Comment
Question by:PeterErhard
6 Comments
 
LVL 8

Accepted Solution

by:
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

by:Ivo Stoykov
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

by:Ivo Stoykov
ID: 16495695
Hi PeterErhard,

sorry misunderstood the question

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

regards

I
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 8

Expert Comment

by:KennyTM
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

by:waygood
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

by:PeterErhard
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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

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

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question