|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
ulyxes Smarty Rookie
Joined: 31 Jan 2007 Posts: 6
|
Posted: Wed Jan 31, 2007 2:15 pm Post subject: number_format modifier, maybe can help out someone |
|
|
I've made this very simple addon, i was surprised there wasn't one and so i wrote it and used it.
Filename to create: modifier.number_format.php
Code: |
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty number_format modifier plugin
*
* Type: modifier<br>
* Name: number_format<br>
* Purpose: returns a formatted number as of php number_format
* @author ulyxes <zulisse at email dot it>
* @param string
* @param string
* @param string
* @param string
* @return string
*/
function smarty_modifier_number_format($string, $decimals = 0, $dec_sep=",", $thous_sep = ".")
{
return number_format($string,$decimals,$dec_sep,$thous_sep);
}
/* vim: set expandtab: */
?>
|
usage:
$smarty->assign('var', 5600000);
{$var|number_format} will output 5.600.000 (EU standards)
{$var|number_format:2} will output 5.600.000,00 (EU standards)
{$var|number_format:2:",":"."} will output 5,600,000.00 (US standards) (u may change default values in the definition function.
number_format:(int_decimals):(string_decimal_separator):(string_thousands_separator)
Sorry if it's a duplicate, it still might help someone out. |
|
Back to top |
|
TGKnIght Smarty Junkie
Joined: 07 Sep 2005 Posts: 580 Location: Philadelphia, PA
|
|
Back to top |
|
ulyxes Smarty Rookie
Joined: 31 Jan 2007 Posts: 6
|
Posted: Thu Feb 01, 2007 11:32 am Post subject: |
|
|
well i didn't know this |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|