Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
2 posts Page 1 of 1
If you parse price_lists or CSV to update prices, you might encounter currency symbols besides, i.e. 3$ or $3. Your editable is to be filled only with '3' without symbols.

Well, such a trimming can be done with Couch hack:
Code: Select all
<cms:number_format price />"

For now this hack works only with symbols AFTER the number.
You can test this right away:
Code: Select all
<cms:set testvar1='3$' />
<cms:set testvar2='$3' />
<cms:show "<cms:number_format testvar1 />" /><br/>
<cms:show "<cms:number_format tesvar2 />" /><br/>

It would give
3.00
0.00

Hope this helps to save some loops.
Hi, trendoman. We could also accomplish this by applying PHP's trim() function by way of a custom tag. The string you want to trim should be the first parameter, currency symbols to be removed are supplied in the second parameter. Of course, you could also use this tag to trim away any other characters you choose.
Code: Select all
<cms:trim_characters "$130.00" "$¥€£¢₡៛₴₱"/>

Additionally, you could use the number_format tag to control the number of decimal places returned.
Code: Select all
<cms:number_format "<cms:trim_characters "£30" "$¥€£¢₡៛₴₱"/>"/>
would return "30.00".

Code: Select all
class TrimCharacters{   
    function trim_characters( $params, $node ){
        global $FUNCS, $CTX;
        if( count($node->children) ) {die("ERROR: Tag \"".$node->name."\" is a self closing tag");}
        return trim( $params[0]['rhs'], $params[1]['rhs'] );
        }
    }
$FUNCS->register_tag( 'trim_characters', array('TrimCharacters', 'trim_characters') );
2 posts Page 1 of 1

Who is online

In total there is 1 user online :: 0 registered, 0 hidden and 1 guest
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 1 guest