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
Solved

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

Posted on 2009-07-03
3
1,334 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
  • 2
3 Comments
 
LVL 12

Assisted Solution

by:kevin_u
kevin_u earned 20 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

837 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