i've got this function where i want to format a number, for example, if it's integer like 79, the function returns it as $79,000,000.00. Otherwise, if it's 79.5, this function returns it as $79,500,000.00.
The function is the following and it's working fine, you can test it on http://www.compileonline.com/execute_php_online.php:
function format_bolsa($number)
{
if(is_int($number))
{
echo '<p style="color:#0B3B0B">I am an INT and the number/value before processing is: ',$number,'</p>';
$number='$'.$number.',000,000.00';
echo '<p style="color:#0B3B0B">I am an INT and now the formatted number is: ',$number,'</p>';
return $number;
}
else if(is_float($number))
{
echo '<p style="color:#0B3B0B">I am a FLOAT and the number/value before processing is: ',$number,'</p>';
$number_tmp=explode('.',$number);
$number='$'.$number_tmp[0].','.$number_tmp[1].'00,000.00';
echo '<p style="color:#0B3B0B">I am a FLOAT and now the formatted number is: ',$number,'</p>';
return $number;
}
echo '<p style="color:#610B0B">Nothing has been done. The number is: ',$bolsa,' but such a value will not be returned!</p>';
}
$number=79;
$number=format_bolsa($number);
echo $number;
Nevertheless, when i insert it inside a class like this (becoming a method):
public function format_bolsa($number)
{
if(is_int($number))
{
echo '<p style="color:#0B3B0B">I am an INT and the number/value before processing is: ',$number,'</p>';
$number='$'.$number.',000,000.00';
echo '<p style="color:#0B3B0B">I am an INT and now the formatted number is: ',$number,'</p>';
return $number;
}
else if(is_float($number))
{
echo '<p style="color:#0B3B0B">I am a FLOAT and the number/value before processing is: ',$number,'</p>';
$number_tmp=explode('.',$number);
$number='$'.$number_tmp[0].','.$number_tmp[1].'00,000.00';
echo '<p style="color:#0B3B0B">I am a FLOAT and now the formatted number is: ',$number,'</p>';
return $number;
}
echo '<p style="color:#610B0B">Nothing has been done. The number is: ',$number,' but such a value will not be returned!</p>';
}
the now method is not working properly and i get my custom message
Nothing has been done. The number is:',$number,' but such a value will not be returned!
I call the method like this:
$number=self::format_bolsa($number);
I don't know why it isn't working. I have inserted other functions like this and they're working fine now as methods.
Anyone can shed some light?