David
David

Reputation: 4895

How to format numbers depending on current language with Laravel

Please correct me if I'm wrong but I think Laravel doesn't come with number translator feature.

Github > laravel/framework > Search string > "number_format"

Anyway, how can I format properly a number depending on the current language in Laravel?

It can be done with number_format according to PHP docs, but I want a general way of doing it other than adding some conditions.

Upvotes: 0

Views: 2600

Answers (1)

user1669496
user1669496

Reputation: 33078

The easiest way would be using the NumberFormatter class which comes with PHP.

$num = NumberFormatter::create('en_US', NumberFormatter::DECIMAL);
echo $num->format(10000000);

For different locales, just pass in a different locale to the constructor.

Upvotes: 7

Related Questions