there is a number and i want to know weather its a +ve number or a -ve number how can i find this?
thanks
dizyn
how to get sign of a number
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
$positive = ($number >= 0);What about 0? 0 isn't positive...feyd wrote:Code: Select all
$positive = ($number >= 0);
I understand what you are saying here... But I don't agree with:feyd wrote:Nor is it negative. So? I'd let itsmani1 choose whether he wants zero to be considered negative or positive or something else.
since it's not open for a discussion... 0 is not positive nor negative.feyd wrote:whether he wants zero to be considered negative or positive or something else.
I still agree with what you are saying in general since there are some cases where you only want to make sure that the number is not negative for example.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
I think the concept Feyd offered is a useful point. Whether the OP wants to check for zero as a value is beside the point. Not to mention that zero, though it is not a negative value, can be associated with positive values as a default non-negative.
But more importantly, Feyd offered a sugestion to get the OP pointed in the proper direction, in my opinion.
But more importantly, Feyd offered a sugestion to get the OP pointed in the proper direction, in my opinion.
Again, I agree with you except to this part: "zero, though it is not a negative value, can be associated with positive values as a default non-negative.".Everah wrote:I think the concept Feyd offered is a useful point. Whether the OP wants to check for zero as a value is beside the point. Not to mention that zero, though it is not a negative value, can be associated with positive values as a default non-negative.
But more importantly, Feyd offered a sugestion to get the OP pointed in the proper direction, in my opinion.
It's right that a non-negative number is a number which is >= 0, that's true, but it still doesn't make zero positive.
Again, I get what you are trying to say guys and I do agree, I'm just a meticulous person... Sorry for that