geroido Posted July 30, 2008 Share Posted July 30, 2008 Hi If I want to display a currency value with the euro symbol at the beginning, do I have to concatenate it on or is there some php function that will format the variable with a particular currency symbol Quote Link to comment https://forums.phpfreaks.com/topic/117339-how-to-format-a-variable-with-a-particular-currency-value/ Share on other sites More sharing options...
craygo Posted July 30, 2008 Share Posted July 30, 2008 Just write a custom function. Here is one and you can expand on the formats <?php function curr_format($curr, $amount){ switch ($curr){ case "EUR": $ret = "€".number_format($amount, 2, ",", " "); break; case "US": $ret = "$".number_format($amount, 2, ".", ","); break; } return $ret; } echo curr_format("EUR", "2568.2523"); // output is €2 568,25 ?> Ray Quote Link to comment https://forums.phpfreaks.com/topic/117339-how-to-format-a-variable-with-a-particular-currency-value/#findComment-603589 Share on other sites More sharing options...
critical-state Posted July 30, 2008 Share Posted July 30, 2008 Hi I did see that there is a money format function listed here: http://www.php.net/manual/en/function.money-format.php although I don't think its fuctional on windows for some reason. very basic but have you tried this: <?php $value = 1234.56; $euro= "€"; $output= $euro.$value; echo $output; ?> Quote Link to comment https://forums.phpfreaks.com/topic/117339-how-to-format-a-variable-with-a-particular-currency-value/#findComment-603637 Share on other sites More sharing options...
geroido Posted July 30, 2008 Author Share Posted July 30, 2008 Hi Critical state Thanks. That worked great. I just initialised the euro variable and concatenate it wherever I want. Perfect Quote Link to comment https://forums.phpfreaks.com/topic/117339-how-to-format-a-variable-with-a-particular-currency-value/#findComment-603770 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.