How to find the magnitude of a variable without sign[SOLVED]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

How to find the magnitude of a variable without sign[SOLVED]

Post by raghavan20 »

Suppose if I have -15 or 15, I should get only 15 the magnitude only.
Is there an in-built function available in PHP?

or

Is there a function to identify the sign of an integer (positive or negative)?
Last edited by raghavan20 on Sat Oct 08, 2005 7:05 am, edited 1 time in total.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

I found another way

Code: Select all

$pad_zeros_length = -34234;
		echo "pad_zeros_length:". $pad_zeros_length;
		$pad_zeros_length = $pad_zeros_length < 0? -($pad_zeros_length):$pad_zeros_length;
		echo "pad_zeros_length:". $pad_zeros_length;
Post Reply