Forum Moderators: coopster
Your integers are strings when you use them that way, so you can do a simple if, to screen for a negative value, and then immediately treat the value as a string, cropping off the - character, and concatenating your parenthesis:
if($value < 0){$value = '(' . substr($value,1) . ')';}
Similarly, you can simply look for the entire money value to be equal to zero, and replace it with the - character if it is. No need to fret about the other digits or characters, since comparing to the numeric 0 will test correctly:
if($value == 0){$value = '-';}
In principle, you can wrap this all up into your own function, to make things easy if you're going to do this in a bunch of places:
function FormatCash($value){
if($value < 0){$value = '(' . substr($value,1) . ')';}
elseif($value == 0){$value = '-';}
return $value;
}
[edited by: ChainsawXIV at 4:06 pm (utc) on Jan. 23, 2008]