[thelist] replacing periods with commas

Brady Mitchell mydarb at gmail.com
Thu Jan 3 15:43:50 CST 2008


On Jan 3, 2008 1:16 PM,  <ftarzwell at fayec.com> wrote:
>
> I have an output file that should display:
> 864,7 $    +8.2
> Instead it's showing:
> 86,.7 $    +,.2
>
> The code that does the replacement of the period for a comma is as follows:
> $change = substr_replace($change, ",", strlen($change) - 3, 1);
>
> Should the code be:
> $change = substr_replace($change, ",", strlen($change) - 2, 1);
>
> in order to fix the comma issue?

Actually, I'd use strtr (http://php.net/strtr) instead:

$change = strtr($change, ',' , '.');

That way you never have to worry about how many digits are in the number.

Brady



More information about the thelist mailing list