format a number

Author Message

Claudia Kosny

Thursday 09 November 2006 1:35:38 am

Hi there

is there a way to format a number similar to PHP's number_format?
I want to make sure that a certain number is always displayed with two decimals, a dot as decimal point and no thousand separator no matter what the locale is.
The si operator requires a unit which I don't want and the l10n operator formats according to the locale as far as I know.

I can certainly write an extension which implements the number_format function of PHP in eZ but I was wondering whether this is possible using existing eZ operators.

Claudia

Xavier Dutoit

Thursday 09 November 2006 1:52:13 am

Hi Claudia,

The default way of adding a php function works only if you have one parameter to this function. I suppose that's not the case for you. I'm afraid it means creating an extension to add this template.

See this doc:

http://ez.no/products/ez_publish/documentation/development/extensions/template_operator

X+

http://www.sydesy.com

Claudia Kosny

Thursday 09 November 2006 2:46:48 am

Hi Xavier

Writing my own extension for this is no problem at all, actually I have done so already meanwhile. I just was wondering whether there is a way to do it using existing eZfunctions as I don't want to add more custom code than necessary.

Claudia

Xavier Dutoit

Thursday 09 November 2006 4:31:04 am

Hi,

You can add php functions as template function from within the template.ini.append

[PHP]
# A list with php functions and their equivelant template operator names
# Giving the operators a different name from the PHP functions
# are recommended, that way you ensure that all operators follow
# the same naming guidelines. It also means that you can change the
# php function later on without doing template changes.
PHPOperatorList[]
PHPOperatorList[urlencode]=urlencode

The only problem is that you can then only use them as $blabla|urlencode() . If the php function you plan to use needs more than one parameter, then you need to write an extension.

X+

http://www.sydesy.com

Xavier Dutoit

Thursday 09 November 2006 4:34:12 am

BTW, could you add your function in the contrib ?

X+

http://www.sydesy.com

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 20 2025 03:59:43
Script start
Timing: Jan 20 2025 03:59:43
Module start 'layout'
Timing: Jan 20 2025 03:59:43
Module start 'content'
Timing: Jan 20 2025 03:59:43
Module end 'content'
Timing: Jan 20 2025 03:59:43
Script end

Main resources:

Total runtime0.0173 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0079 589.0234152.6094
Module start 'layout' 0.00790.0025 741.632839.3984
Module start 'content' 0.01040.0053 781.031393.3828
Module end 'content' 0.01570.0016 874.414134.3047
Script end 0.0173  908.7188 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002313.4080140.0002
Check MTime0.00116.3135140.0001
Mysql Total
Database connection0.003922.748010.0039
Mysqli_queries0.002011.706730.0007
Looping result0.00000.074410.0000
Template Total0.00137.310.0013
Template load0.00063.530710.0006
Template processing0.00063.738810.0006
Override
Cache load0.00042.420410.0004
General
dbfile0.00137.700780.0002
String conversion0.00000.045540.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs