P: n/a

This is an easy question, I'm sure but I can't seem to figure it
out.
I'm trying to use the number_format() function to remove all decimal
places from a number.
$num = number_format($num, 0, '.', '');
So if I have 23.34567 I want 23, and 45.8789 will return with 45.
The problem is that the this function rounds the number off. so that
45.8789 returns 46 instead of 45.
Is there another function? What should I be using.
Thanks for your help.  
Share this Question
P: n/a

rynTAU wrote:
This is an easy question, I'm sure but I can't seem to figure it
out.
I'm trying to use the number_format() function to remove all decimal
places from a number.
$num = number_format($num, 0, '.', '');
So if I have 23.34567 I want 23, and 45.8789 will return with 45.
The problem is that the this function rounds the number off. so that
45.8789 returns 46 instead of 45.
Is there another function? What should I be using.
Thanks for your help.
$num = int($num);

==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================  
P: n/a

"rynTAU" <rt****@gmail.comwrote in message
news:11*********************@h3g2000cwc.googlegrou ps.com...
This is an easy question, I'm sure but I can't seem to figure it
out.
I'm trying to use the number_format() function to remove all decimal
places from a number.
$num = number_format($num, 0, '.', '');
So if I have 23.34567 I want 23, and 45.8789 will return with 45.
The problem is that the this function rounds the number off. so that
45.8789 returns 46 instead of 45.
Is there another function? What should I be using.
Thanks for your help.
You just need to cast to an integer, ie:
$num= 23.34567;
$num = (int) $num;
$num then equals 23,
cheers,
ED  
P: n/a

Thanks, I knew it was something so easy that I couldn't find anything
about it online. :)
On Feb 21, 10:53 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
rynTAU wrote:
This is an easy question, I'm sure but I can't seem to figure it
out.
I'm trying to use the number_format() function to remove all decimal
places from a number.
$num = number_format($num, 0, '.', '');
So if I have 23.34567 I want 23, and 45.8789 will return with 45.
The problem is that the this function rounds the number off. so that
45.8789 returns 46 instead of 45.
Is there another function? What should I be using.
Thanks for your help.
$num = int($num);

==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
 
P: n/a

Jerry Stuckle wrote:
>
rynTAU wrote:
This is an easy question, I'm sure but I can't seem to figure it
out.
I'm trying to use the number_format() function to remove all decimal
places from a number.
$num = number_format($num, 0, '.', '');
So if I have 23.34567 I want 23, and 45.8789 will return with 45.
The problem is that the this function rounds the number off. so that
45.8789 returns 46 instead of 45.
Is there another function? What should I be using.
Thanks for your help.
$num = int($num);
I would advise against type casting. It can produce strage results under
some circumstances.
He would be better of using $num = floor($num), that's what the function
is here for.
ceil() always rounds up, floor() always rounds down, round() rounds
according to mathematical rules (down on .0 to .4, up on .5 to .9
Bye!  
P: n/a

Anonymous wrote:
Jerry Stuckle wrote:
>rynTAU wrote:
>>This is an easy question, I'm sure but I can't seem to figure it out.
I'm trying to use the number_format() function to remove all decimal places from a number.
$num = number_format($num, 0, '.', '');
So if I have 23.34567 I want 23, and 45.8789 will return with 45. The problem is that the this function rounds the number off. so that 45.8789 returns 46 instead of 45.
Is there another function? What should I be using.
Thanks for your help.
$num = int($num);
I would advise against type casting. It can produce strage results under
some circumstances.
He would be better of using $num = floor($num), that's what the function
is here for.
ceil() always rounds up, floor() always rounds down, round() rounds
according to mathematical rules (down on .0 to .4, up on .5 to .9
Bye!
And int() always truncates and returns an integer  which is exactly
what he wants. See the doc.

==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================  
P: n/a

Jerry Stuckle wrote:
rynTAU wrote:
>This is an easy question, I'm sure but I can't seem to figure it out.
I'm trying to use the number_format() function to remove all decimal places from a number.
$num = number_format($num, 0, '.', '');
So if I have 23.34567 I want 23, and 45.8789 will return with 45. The problem is that the this function rounds the number off. so that 45.8789 returns 46 instead of 45.
Is there another function? What should I be using.
Thanks for your help.
$num = int($num);
Actually, Jerry, your code would produce an E_USER_FATAL, since there
is no builtin function called int(). Any of these will work:
$n = 25.2829;
$n = (int) $n;
$n = intval($n);
$n = floor($n);

Curtis, http://dyersweb.com  
P: n/a

Hi
Anonymous wrote:
Jerry Stuckle wrote:
>$num = int($num);
I would advise against type casting. It can produce strage results under
some circumstances.
He would be better of using $num = floor($num), that's what the function
is here for.
ceil() always rounds up, floor() always rounds down, round() rounds
according to mathematical rules (down on .0 to .4, up on .5 to .9
What's about minus values?
We don't know what the OP would like to get.
floor(2.8) =3
(int)2.8 =2
HTH, Johannes  
P: n/a

Johannes Vogel wrote:
Hi
Anonymous wrote:
>Jerry Stuckle wrote:
>>$num = int($num);
I would advise against type casting. It can produce strage results under some circumstances. He would be better of using $num = floor($num), that's what the function is here for. ceil() always rounds up, floor() always rounds down, round() rounds according to mathematical rules (down on .0 to .4, up on .5 to .9
What's about minus values?
We don't know what the OP would like to get.
floor(2.8) =3
(int)2.8 =2
HTH, Johannes
int(2.8) is 2, as you indicated. And the operator indicated he wanted
to truncate the value, so floor() would in this case provide an
incorrect value.
Now if he said he wanted the next lower integer, your solution would be
correct.

==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================  
P: n/a

Curtis wrote:
Jerry Stuckle wrote:
>rynTAU wrote:
>>This is an easy question, I'm sure but I can't seem to figure it out.
I'm trying to use the number_format() function to remove all decimal places from a number.
$num = number_format($num, 0, '.', '');
So if I have 23.34567 I want 23, and 45.8789 will return with 45. The problem is that the this function rounds the number off. so that 45.8789 returns 46 instead of 45.
Is there another function? What should I be using.
Thanks for your help. $num = int($num);
Actually, Jerry, your code would produce an E_USER_FATAL, since there is
no builtin function called int(). Any of these will work:
$n = 25.2829;
$n = (int) $n;
$n = intval($n);
$n = floor($n);

Curtis, http://dyersweb.com
<sheepish grin>
Been doing too much C++ lately, I guess :)
Thanks for the correction.

==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================   This discussion thread is closed Replies have been disabled for this discussion.   Question stats  viewed: 1595
 replies: 9
 date asked: Feb 21 '07
