Re: var type
| From: | Steve Edberg | Date: | Mon, 18 Dec 2000 19:44:57 +0000 |
| Subject: | Re: var type | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-30899@lists.php.net to get a copy of this message | ||
I don't know the details of your application, so this might not work well, but why not leave these numeric strings as numeric types (leave out the punctuation), and use one of the following functions to format the numbers when you need to output them:
http://www.php.net/manual/function.number-format.php
http://www.php.net/manual/function.sprintf.php
http://www.php.net/manual/function.printf.php
That makes more sense to me --- but then I don't know what your particular application is !
Also (as is mentioned in the reference Philip gave) most PHP functions are able to convert types on-the-fly, so you can use a numeric type in a string expression (for formatting) and it will work fine.
- steve
At 7:22 PM +0000 12/18/00, Philip Olson wrote:
Hey Thomas- Read : http://www.php.net/manual/language.types.type-juggling.php Regards, Philip --.sigOh yeah... in this case you can also compare strings via strcmp(), in PHP >= 3.0.16 (I think): http://www.php.net/manual/function.strcmp.php (and I assume in your real program you use the variables $string1 and $string2...) +--- "They've got a cherry pie there, that'll kill ya" ------------------+[ Want to write Good code? First, write Bad code. ]On Mon, 18 Dec 2000, Thomas Holton wrote: Hello, I have strings that contain numbers... this is because it is easier to insert chars into strings of numbers for prettier displays. However, now that i want to compare these strings NUMERICALLY, i cannot. IOW: string1 = "2001"; string2 = "2002"; if( string2 >= string1 ) { ... but this is never true, as it should be. How can i integerize these strings for simple numerical comparison. thanks
| Steve Edberg University of California, Davis | | sbedberg@ucdavis.edu Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ |+-------------------------------------- FBI Special Agent Dale Cooper ---+