2

In an international web app, we deal with currencies like this:

USD: 2,400.55 EUR: 2.400,55

I need to be able to print those number as 2400.55 (for usd) and 2400,55 (for EUR) The problem is that I don't know in advance what kind of currency is coming at me.

No matter what the number format is, I'd like to use a function that only strips out the thousand separator, no matter if that is a , or a .

The number_format didn't solve my issue as far as I could see. Any tips on this?

Zoe
  • 27,060
  • 21
  • 118
  • 148
Jorre
  • 17,273
  • 32
  • 100
  • 145
  • How is the application supposed to change the money value if you don't give it the input currency? – Shoe Feb 05 '11 at 12:13
  • Don't you gonna say that these numbers being stored in the `2,400.55` format, do you? – Your Common Sense Feb 05 '11 at 12:14
  • possible duplicate of [how do i print currency format in php](http://stackoverflow.com/questions/4013950/how-do-i-print-currency-format-in-php) – Gordon Feb 05 '11 at 12:20
  • possible duplicate of [Is there a PHP function to format a currency amount in accounting format](http://stackoverflow.com/questions/1625717/is-there-a-php-function-to-format-a-currency-amount-in-accounting-format) – Gordon Feb 05 '11 at 12:21
  • *(tip)* [Devzone: I10n in PHP](http://devzone.zend.com/article/4799) – Gordon Feb 05 '11 at 12:22
  • everything is stored unformatted as 2500.55 in the database – Jorre Feb 05 '11 at 12:41
  • so, your question is just how to replace a dot with comma? Great. That's what I call logic – Your Common Sense Feb 05 '11 at 13:26
  • @Gordon, your link is not a duplicate, because in that question the asker *wants* the thousands separator. In this question the asker wants to avoid it. – finnw Feb 05 '11 at 14:28
  • @finnw It is a duplicate because the solution is the same. StackOverflow does not need one question for every possible combination of arguments you can pass to a function. People should learn to read an API and how to abstract. The question is about internationalization and not just about adding or removing a separator. – Gordon Feb 05 '11 at 14:32
  • Hi Gordon, I know how to format currencies in php. I couldn't and still can't find a decent way to remove the thousand separator as the money_format function doesn't exist on windows. – Jorre Feb 09 '11 at 11:03

1 Answers1

3

Take a look at money_format function for that.

Note:

The LC_MONETARY category of the locale settings, affects the behavior of this function. Use setlocale() to set to the appropriate default locale before using this function.

Sarfraz
  • 377,238
  • 77
  • 533
  • 578
  • I coded it with the money_format function, by passing the locale to it and by stripping the thousand separator with the ^ option. – Jorre Feb 05 '11 at 13:16
  • Sorry, guys, this function is not supported on windows and crashes the application. I'm looking for an alternative here. – Jorre Feb 09 '11 at 11:02