|
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 |
cypreess Smarty Rookie
Joined: 04 Sep 2004 Posts: 10
|
Posted: Sat Sep 04, 2004 5:12 pm Post subject: math | string format |
|
|
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 |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Sat Sep 04, 2004 6:00 pm Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Sun Sep 05, 2004 2:45 pm Post subject: |
|
|
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 |
|
cypreess Smarty Rookie
Joined: 04 Sep 2004 Posts: 10
|
Posted: Mon Sep 06, 2004 10:51 pm Post subject: |
|
|
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 |
|
|
|
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
|