I am working with CSV files and Excel often format prices like this:
$ 384.642,54
Where the Decimal is 54. I need to round this number to 384.643
(always round up).
What I've done is first: Remove spaces and the $ sign that excel puts in the cell.
What I have now is this number 384.642,54
. I need PHP to know the decimal is the Coma and the dot is the thousand separator, then round it.
I haven't been able to achieve this with number_format. It returns me 384
Simplest and the least involved solution: use
str_replace
to replace dots with empty string; then use it again to replace comma with dot; then usefloatval
to convert string to number and then round it any way you want:There you go:
As stated in my comment, the least invasive way is to str_replace() the unwanted parts. And then use
ceil()
to round-up.Optionally you can use preg_replace() to 'smart' replace things, but for this setup it's not cost effective.