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)?
How to find the magnitude of a variable without sign[SOLVED]
Moderator: General Moderators
- 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]
Last edited by raghavan20 on Sat Oct 08, 2005 7:05 am, edited 1 time in total.
- n00b Saibot
- DevNet Resident
- Posts: 1452
- Joined: Fri Dec 24, 2004 2:59 am
- Location: Lucknow, UP, India
- Contact:
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
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;