RE: [SMARTY] Comparing numbers

From: Date: Tue, 06 Apr 2004 14:59:26 +0000
Subject: RE: [SMARTY] Comparing numbers
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-11237@lists.php.net to get a copy of this message
>>>Hi there, >>> >>>I have a need to compare two numbers, and if one is greater than the >>>other, output some stuff. >>> >>>In this example, {$Events[i].monthnum} = 03 >>> {$Month} = 04 >>> >>>{if $Events[i].monthnum > $Month} >>>do stuff here >>>{/if} >>> >>>This fails. So thinking it was perhaps the leading zero, I tried the >>>following, which failed equally: >>> >>> >>In case of the obvious, 3 > 4 should fail (false). >> >> >>>{if $Events[i].monthnum|regex_replace:"/^0/":" " > >>>$Month|regex_replace:"/^0/":" "} >>> >>>So, then I tried: >>> >>>{if $Events[i].monthnum|string_format:"%d" > >>> >>> >$Month|string_format:"%d"} > > >>>And this fails too. >>> >>>So now I am really stumped. Any tips? My Smarty version is 2.3.1. >>> >>>-Erich- >>> >>> >>> >>> >>Sorry, should have been more specific: >> >>{if $Events[i].monthnum|string_format:"%d" > $Month|string_format:"%d"} >> <table><tr><td>Hello World</td></tr></table> >>{/if} >> >>In this code, it is always printing out Hello World, even when >>{$Events[i].monthnum} is equal to 3 and {$Month} is equal to 4. That's >>what I mean when I say it fails. >> >>-Erich- >> >> >>What does this produce? >> >>{$Events[i].monthnum|string_format:"%d"} >>{$Month|string_format:"%d"} >> >> >3 and 4, where they used to be 03 and 04 respectively. > >-Erich- > > Strange. Did you try: > > * "gt" instead of ">" > * latest version of Smarty Yes: {if $Events[i].monthnum|string_format:"%d" gt $Month|string_format:"%d"} echo "Version = $smarty->_version"; => 2.6.2 -Erich-

« previous php.smarty.general (#11237) next »