Jump to content

[SOLVED] removing place values from a number - very easy Q


aebstract

Recommended Posts

I don't want to round, I need to keep my numbers pretty exact. I was using a rounding method to do this and while I was testing possibilities I ran in to a problem which is why I need to just remove the numbers now.

 

 

edit: is there an easy way to remove all characters of a string except for the first two?

the manual will help you with the details, but you want one of round(), ceil(), float(), or number_format() depending on how you want the chopping to occur.

 

http://www.php.net is your best friend.

 

EDIT:  beaten to the punch, but you don't need to create a function.  one already exists for truncating decimals.

I don't want to round my number though, and number format seems to only place a comma in my number. If I go that way the only thing I can see doing is to put a comma every two numbers and explode and use the first value in my array. That'd be doing a little bit more than I wanted to but at least I can do that if I have to.

Well, after looking at number_format a little bit more, it just goes in thousands (3 places) which won't help me keep the first 2 separated from the rest of the pack.

 

 

 

EDIT: knew this was something very easy, and I have found the solution::

substr('5054056412', 0, 2);

cake

... you probably didn't read the manual entry correctly for number_format():

 

echo number_format(1.52524233, 2);

 

from the manual:

 

decimals

 

    Sets the number of decimal points.

 

no reason to use substr().

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.