2

I use this line of code

echo number_format  ($debit_sum_500to791,2);

Then it echo me the value if its Plus or minus

I want to filter the value of PLUS or Minus and get only the numbers.

example: if its -10 i need only 10

So i use this way

echo (number_format  ($debit_sum_500to791,2),FILTER_SANITIZE_NUMBER_INT);

but it does not working, come empty blank page

I think im not doing it right, so can any one help me with this problem ?

Ron van der Heijden
  • 14,803
  • 7
  • 58
  • 82
user3214631
  • 43
  • 1
  • 5

3 Answers3

2

Just use abs

Any negative or positive value will become positive.

dan-lee
  • 14,365
  • 5
  • 52
  • 77
1

try like

filter_var($str, FILTER_SANITIZE_NUMBER_INT);

or

$str= '-10';
preg_match_all('!\d+!', $str, $matches);
echo $matches[0][0]; // 10

For more :- Extract numbers from a string

Community
  • 1
  • 1
Rakesh Sharma
  • 13,680
  • 5
  • 37
  • 44
  • the original value i get -0.02, after the filter -002, but still with the minus sign. i am after result is 0.02 – user3214631 May 07 '14 at 11:38
1

Try with php abs() function ref: http://www.php.net/manual/en/function.abs.php