Jump to content

mysterious '0' appear with this function


2DaysAway

Recommended Posts

Ok, I have a list of these functions on a separate php file and I use the include() statement on another php file to load this function page into it. The functions work properly but for every function I use a 0 appears at the top of the DIV the include() statement is in. So, I have exactly nine 0's in a row because I have nine separate functions. Any ideas what is going on here? lol.

 

$mint = $user["medicine"];
function mformat($number) {
$suffix = array('', ' K', ' M', ' B',' T', ' Q');
$max = count($suffix) - 1;
while ($number >= 1000 and $i < $max){
	$number /= 1000;
	$i++;
}
$number = round($number, 2);
return $number . $suffix[$i];
}
echo mformat($mint);

Link to comment
https://forums.phpfreaks.com/topic/126959-mysterious-0-appear-with-this-function/
Share on other sites

Must be coming from somewhere else, because I just did:

 

<?php
$mint = 56000;
function mformat($number) {
$suffix = array('', ' K', ' M', ' B',' T', ' Q');
$max = count($suffix) - 1;
while ($number >= 1000 and $i < $max){
	$number /= 1000;
	$i++;
}
$number = round($number, 2);
return $number . $suffix[$i];
}
echo mformat($mint);

 

And it worked fine.  Are you sure $user['medicine'] is not null?

You are probably echoing a false value (treated as a number).

 

For anyone in a forum to help, you would need to post the relevant code that is producing and outputting content immediate prior to the <div>, i.e. the code responsible for the point in the output where the zero is appearing.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.