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

math | string format

 
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 -> Feature Requests
View previous topic :: View next topic  
Author Message
cypreess
Smarty Rookie


Joined: 04 Sep 2004
Posts: 10

PostPosted: Sat Sep 04, 2004 5:12 pm    Post subject: math | string format Reply with quote

hello .

i have got someting like this
Code:

{if $fsize < 1024}
             {$fsize} B
{elseif $fsize < 1048576}
            {(math equation="size / 1024" size=$fsize)|string_format:"%.2f"} KB
{else}
            {(math equation="size / 1024 / 1024" size=$fsize)|string_format:"%.2f"
{/if}


This should print SIZE OF FILE depending on value in B, KB or MB. but the STRING_FORMAT doesnt work and i've got for example:

34.453534545 MB

what to do ???????
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Sat Sep 04, 2004 6:00 pm    Post subject: Reply with quote

to apply a modifier to math, this should work:

Code:
{math|string_format:"%.2f" equation="size / 1024" size=$fsize} KB
...
{math|string_format:"%.2f" equation="size / 1024 / 1024" size=$fsize} MB
Back to top
View user's profile Send private message Send e-mail Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Sun Sep 05, 2004 2:45 pm    Post subject: Reply with quote

Another option is to use a custom modifier:

{$bytes|fsize_format}

Then you can do all this math in PHP and reuse the formatting quickly and easily.
Back to top
View user's profile Send private message Visit poster's website
cypreess
Smarty Rookie


Joined: 04 Sep 2004
Posts: 10

PostPosted: Mon Sep 06, 2004 10:51 pm    Post subject: Reply with quote

Thanks !!!

That works FINE !!


And something diffrent by the way.
Code:

$my_date = " 2004-09-04 15:06:19.782843"; 
//this is value got from POSTGRESQL timestamp

and i do in tempate:
Code:

{$my_date|date_format:"%Y.%m.%d %H:%M"}

and this prints : 1970.01.01 01:33
and without date_format it prints: 2004-09-04 15:06:19.782843

WHY WHY WHY ? I have used date_format in anather project with postgres timestamps and everything works good. whats going on ? i had ctrl_copy ctrl+paste this from other project and hadnt help.
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 -> Feature Requests 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