View unanswered posts | View active topics It is currently Sat Nov 01, 2014 12:15 am



Reply to topic  [ 3 posts ] 
 PHP string trimming 
Author Message
Site Admin

Joined: Tue Aug 06, 2002 7:01 am
Posts: 24
Location: Thunder Bay, ON, CA
Post PHP string trimming
Quick question (hopefully with a quick answer [img]images/smiles/icon_wink.gif[/img] )... Is there a way to trim strings in PHP to a certain length.

Reason being, I am calculating percents in my script and am getting really long number when I just want it rounded to say one decimal. Is there a function for this or must I write my own?

Thanks in advance for any help [img]images/smiles/icon_smile.gif[/img] .


Sat Dec 27, 2003 1:48 am
Profile WWW

Joined: Wed Dec 31, 2003 8:01 am
Posts: 1
Location: UK
Post PHP string trimming
well if your askin whether decimals can be forced to 1 d.p they can. Look at the function round at php.net


Thu Jan 01, 2004 2:07 am
Profile WWW

Joined: Mon Aug 18, 2003 7:01 am
Posts: 27
Post PHP string trimming
float round ( float val [, int precision])

Returns the rounded value of val to specified precision (number of digits after the decimal point). precision can also be negative or zero (default).

so...
round(3.5) = 4
round(3.4) = 3
round(4/3,2) = 1.33
round(5/3,1) = 1.7

-Ed


Tue Jan 06, 2004 12:43 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware.