master82 Posted August 24, 2006 Share Posted August 24, 2006 Hello All,I'm trying to create the function named fm [[i]money formatter[/i]] to, err well, format my money!Hers is what I have:[code]<?phpfunction mf($money){$symb = '£';number_format($money);echo"$symb$money";}//TO TEST BELOW//Print"Testing: ";mf(1000);?>[/code]Seems very simple, it SHOULD have formatted the number (ie 10000 = 10,000) and added a currency symbol before it.However, the number_format part doesnt seem to work as I get results such as £10000 when I test, and not the £10,000 I was hoping for.Anyone know what I did wrong or another way to do this?Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/18576-number_format-in-custom-function/ Share on other sites More sharing options...
master82 Posted August 24, 2006 Author Share Posted August 24, 2006 Nevermind - worked out my simple mistake. Never pjut the numver_format into a usable variable.[code]<?phpfunction mf($money){$symb = '£';$formatted = number_format($money);echo"$symb$formatted";}//TO TEST BELOW//Print"Testing: ";mf(1000);?>[/code] Link to comment https://forums.phpfreaks.com/topic/18576-number_format-in-custom-function/#findComment-80010 Share on other sites More sharing options...
kenrbnsn Posted August 24, 2006 Share Posted August 24, 2006 You probably want to have your function return the string instead of echoing it.[code]<?phpfunction mf($mny,$symb='£') { return($symb . number_format($mny,2));}echo 'Testing: ' . mf(10000);?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/18576-number_format-in-custom-function/#findComment-80026 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.