How to round 5.2344 to 5.2 ?

Author Message

Mieczyslaw Morzonek

Monday 06 September 2004 1:21:03 am

I don`t know how to round number 5.2344 to 5.2 ?

I tried with shorten() but i doesn`t work :(

{let var=5.2344}

{$var|shorten(3, '')}

{/let}

When i use round function i have only 5 but i need to display 5.2 or 5.23. How to do that?

Finally i must round my poll result to 00.0 or 00.00

{div(mul($:item_count,100),$total_count)|shorten(4. '')} 

//in ez 3.4.1 this code works fine but in ez 3.3-3 it doesn`t work

Pleas help me to solve my problem

thanks for any help

Tobias Persson

Monday 06 September 2004 6:57:27 am

To solve the first I would do something like:

{let var=5.2344}

{$var|mul(10)|round()|div(10)}

{/let}

use 100 instead of 10 if you want 5.23

Mieczyslaw Morzonek

Monday 06 September 2004 7:41:38 am

Ok, i`ve give up :(

I can`t round result from polls to 00.0 or 00.00 ...


{concat(div(mul($:item_count,100),$total_count))|shorten(4. '')} %

this code always show 33.333333333% when 100/3

Tobias Persson

Monday 06 September 2004 8:54:10 am

I'm abit confused about what you try to do.
Do you always want two digits infront of the '.' and one digit behind the '.'

so the transform is something like this?

0 => 00.0
1.5 => 01.5
12.2 => 12.2

Mieczyslaw Morzonek

Tuesday 07 September 2004 4:25:35 am

for example:

result of this code {div(mul($:item_count,100),$total_count)} % is 33.333333333 % . I don`t know how to short this 33.333333333 % to 33.33% or 33.3%

Paul Borgermans

Tuesday 07 September 2004 5:53:11 am

If english is your locale, (others may work too), you can use the l10n operator:

{$yournumber|l10n(number)}

In the english locale, it will display numbers with two decimal places

hth

-paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

Mieczyslaw Morzonek

Tuesday 07 September 2004 6:28:10 am

Thank you Paul it works, now i`ve got 33.33% but is possible change this 33.33% to 33.3%?

Finally i need 33.3%

Thanks for your help

Tobias Persson

Tuesday 07 September 2004 7:00:33 am

Didn't this work? (maybe it doesn't for EZ 3.3-3 ?)

{$var|mul(10)|round()|div(10)}

Mieczyslaw Morzonek

Tuesday 07 September 2004 7:03:49 am

No, it doesn`t work :(

{div(mul($:item_count,100),$total_count)|l10n(number)} this code shows 33.33% i need 33.3%

your code shows always 1%

Paul Borgermans

Tuesday 07 September 2004 7:17:52 am

We need a template operator for number formatting, which should be easy by implementing the php function sprintf. Any takers?

-paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

Christoph von Siebenthal

Monday 01 November 2010 5:47:38 am

Hello Paul

Is that stil on the to do list?

I need it. I take it.

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