Solved

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

Posted on 2009-07-03
3
1,275 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
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.

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now