Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting numbers with thousands separator Smarty PHP

Tags:

smarty

Im trying to format numbers with thousands separator Smarty.

So for example 1000 becomes 1,000.

Thanks.

like image 409
babadbee Avatar asked Jul 07 '10 10:07

babadbee


People also ask

How to separate numbers with commas in php?

The number_format() function rounds numbers and adds commas as a thousands separator. You can pass it either one, two, or four parameters: number_format($n) rounds $n to the nearest whole number and adds commas in between thousands.

How to do number formatting in php?

PHP | number_format() Function $number: It is required parameter which specified the number to be formatted. If no other parameters are set, the number will be formatted without decimals and with the comma (, ) as the thousands separator. $decimals: It is optional parameter and used to specifies decimals.


2 Answers

or you can use php function inside smarty, this is for number_format, you can use other php function too :)

PHP : number_format($number, 2, '.', ',');  SMARTY : {$number|number_format:2:".":","} 
like image 160
Puaka Avatar answered Sep 27 '22 19:09

Puaka


or just in smarty use {$var|number_format:0}

like image 20
huncyrus Avatar answered Sep 27 '22 20:09

huncyrus