|
|
|
Register •
FAQ
• Search • Login
|
|
Page 1 of 1
|
[ 3 posts ] |
|
| Author |
Message |
|
Hackin
Site Admin
Joined: Tue Aug 06, 2002 7:01 am Posts: 24 Location: Thunder Bay, ON, CA
|
 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 |
|
 |
|
bluesaga
Joined: Wed Dec 31, 2003 8:01 am Posts: 1 Location: UK
|
 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 |
|
 |
|
edhaber
Joined: Mon Aug 18, 2003 7:01 am Posts: 27
|
 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 |
|
 |
|
|
Page 1 of 1
|
[ 3 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 2 guests |
|
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
|
|