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! Quote Link to comment 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] Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.