Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Concatenate a % (percentage sign) to a variable (string) in PHP

Posted on 2009-07-03
3
Medium Priority
?
1,495 Views
Last Modified: 2012-05-07
I have what seems to be an easy question for a PHP programmer.

I am trying to concatenate a % (percentage sign) to a variable stored as a string in PHP, however, I can't seem to locate the correct syntax.  

Any help would be appreciated.
$sickTimePercent = (round((($sickTime/$T002_Sum) * $T001_Percent[0]),2))."%";

Open in new window

0
Comment
Question by:jsbxpge
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 12

Assisted Solution

by:kevin_u
kevin_u earned 80 total points
ID: 24774099
it seems to work for me.. I made up some values.

$sickTime = 1;
$T002_Sum = 40;
$T001_Percent[0] = 100;
$sickTimePercent = (round((($sickTime/$T002_Sum) * $T001_Percent[0]),2))."%";
print $sickTimePercent;

Yields the string 2.5%

0
 

Accepted Solution

by:
jsbxpge earned 0 total points
ID: 24774124
Hmm, I wonder if we are using different versions.  I am using version 4.4.9.  I found a solution.  "%25%" seemed to work for me.  Thanks for your help.
0
 
LVL 12

Expert Comment

by:kevin_u
ID: 24774130
I tried it with 5.1.6, but hat is very basic syntax that should have worked.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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 …

722 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