Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

motinska94's avatar

number format with dots and commas switched

I've been using number_format($num, 2) on a project that I've been developing for quite a while now.

But I just realized that my country (Turkey) uses them other way around 😅

Turns out we use 123.456,00 instead of 123,456.00

I noticed that I can fix this by doing number_format($num, 2, ',', '.') but I've used it on many (m a n y) different places now. Is there a way that I can fix this for all of the formatted numbers I've written before?

I tried 'locale'=> 'tr' in config/app.php file since number_format allegedly formats it in the set country's currency format, but it didn't do anything.

0 likes
5 replies
jlrdw's avatar

Use a grep tool, most ide's will grep.

1 like
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Just make your own helper function that that does it for you

function number_format_turkey($num)
{
    return number_format($num, 2, ',', '.');
}

Now replace all usages with your own function

1 like
motinska94's avatar

@Sinnbeck thanks, that's exactly what I did just a second ago and came back to share my solution 😄 I'll post it anyway, maybe it'll help someone else.

in case anyone else has the same problem just add a helper function like :

function number_format_tr($number, $decimals){
	return number_format($number, $decimals, ',', '.');
}

and replace everything in the views (also controllers if you used number_format there too) with search : number_format( replace : number_format_tr(

CTRL + SHIFT + R is pretty useful on PhpStorm.

jlrdw's avatar

@motinska94

Is there a way that I can fix this for all of the formatted numbers I've written before?

I apologize if I misunderstood the question, I thought you were looking for an easy way to replace the occurrences which would be a grep tool.

Please or to participate in this conversation.