Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

number_format modifier, maybe can help out someone

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
ulyxes
Smarty Rookie


Joined: 31 Jan 2007
Posts: 6

PostPosted: Wed Jan 31, 2007 2:15 pm    Post subject: number_format modifier, maybe can help out someone Reply with quote

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
View user's profile Send private message
TGKnIght
Smarty Junkie


Joined: 07 Sep 2005
Posts: 580
Location: Philadelphia, PA

PostPosted: Wed Jan 31, 2007 2:37 pm    Post subject: Reply with quote

What's wrong with PHP's number_format?

PHP functions can be used as modifiers without the need for creating a plugin..

http://smarty.php.net/manual/en/language.modifiers.php
_________________
Smarty site with one index.php controller file
Working with MySQL and Smarty
SmartyColumnSort
Custom Smarty Javascript Debug Template
Back to top
View user's profile Send private message Visit poster's website
ulyxes
Smarty Rookie


Joined: 31 Jan 2007
Posts: 6

PostPosted: Thu Feb 01, 2007 11:32 am    Post subject: Reply with quote

well i didn't know this Smile
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP