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. 9 1880
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
==================
"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
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
==================
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!
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
==================
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 built-in function called int(). Any of these will work:
$n = 25.2829;
$n = (int) $n;
$n = intval($n);
$n = floor($n);
--
Curtis, http://dyersweb.com
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
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
==================
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 built-in 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 thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Russ Perry Jr |
last post by:
I'm using "ID" and "Value" in the generic sense here...
Let's say one page I had a <html:select> with a collection like this:
<html:options collection="items" property="key"...
|
by: PatchFactory Support |
last post by:
Description:
Professional and easy-to-use patch building environment that can help
you to create instant patch packages for software and file updating.
Generated patch packages are small size...
|
by: NBURGAN |
last post by:
We are currently searching for a reporting tool with graphics for our
end users who are using Oracle's standard edition. We are not using
the Oracle's AS. The tool needs to be easy to use and...
|
by: tencip |
last post by:
Hi everyone,
So, I'm running data through an array, and having a little difficulty
in using the number_format function. You see, I'm trying to get a
comma to appear for the thousandths place,...
|
by: Adam Clauss |
last post by:
I have a folder containing many subfolders (and subfolders and....) all containing various .cs files. Is there any "easy" way to
get them all added to the solution. Preferable would be that the...
|
by: Mad Scientist Jr |
last post by:
can someone explain how to simply populate a grid in .net ? the way i
understand it, there is no more msflexgrid, and instead is this new
control that has to be tied to a dataset, and it is a real...
|
by: jacob navia |
last post by:
I am trying to compile as much code in 64 bit mode as
possible to test the 64 bit version of lcc-win.
The problem appears now that size_t is now 64 bits.
Fine. It has to be since there are...
|
by: whitey |
last post by:
Hi All,
How do i define the number_format function to display the currency. it is showing dollars, and i want pounds
thanks
|
by: TheServant |
last post by:
I have realized something which is going to be a headache in the rest of my current project. I don't know how I have not come across this before but let me show you an example:
$x = number_format(...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |