ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Displaying and sorting of numeric data (Dutch annotation)

October 29, 2008 12:37pm

Subscribe [2]
  • #1 / Oct 29, 2008 12:37pm

    Per

    45 posts

    Hi,

    We are setting up a website with EE 1.6.1 for a real estate agency.
    At first we did not know how to sort different houses/object on price as a search result. We found some clues in the forum that said ‘change in MySQL the data field to numeric (that contained the prizes that were filled in into a custom field). We managed to solve that case. Not mentioned in the forum, but it was the decimal we had to choose. It was a little strange to find out that this issue was so superficially described. We could not find anything about sorting numbers in the manual that could have helped us out. Also wondering why this is not a custom field option (decimal or numeric). But ok, solved.

    Now we would like to know how to get an easy way of displaying it in the right Dutch annotation:

    We don’t need a Euro sign, we don’t need the decimals behind the comma. We need points after thousands, like this:

    100.000 (= hundred thousand euro’s in Dutch etc.)
    150.000
    2.300.000

    If we publish a new item and put in the price, like 120.000 then EE shows this in the result entry as 120

    We now can put in the price like 120000 (without the point). But the annotation on the webpage should be or become: 120.000
    (hunderd and twenty thousand).

    {title}
    {price}
    {adress}

    We prefer to not adjust the datbase again or do magic tricks with php (which we do not know much about). We just would like to have this handled in the right way by Expression Engine.

    Is that possible? Is it simple?

    Thanks in advance.

  • #2 / Oct 29, 2008 1:09pm

    Robin Sowell

    13255 posts

    It’s not discussed in the manual because EE doesn’t have a custom field type of ‘numeric’.  So that’s really more of a feature request at this point. 

    I suspect if the numbers are actually in correctly, you’d need to format them using php on output- see the number_format function.  It would be a simple job to roll that into a plugin as well.

    Make sense?

    But since EE doesn’t have a number field at the moment, I’m going to shift over to ‘How to’ for tweaking this one out.  Adding in a number field and allowing formatting of that field would make a good feature request, though.  Something along the lines of how custom date fields are handled would make sense to me.

  • #3 / Oct 29, 2008 1:30pm

    Ingmar

    29245 posts

    We are setting up a website with EE 1.6.1 for a real estate agency.

    If this is a new site, I strongly recommend to upgrade to the latest version. EE 1.6.1 is almost a year old, there have been numerous bugfixes and improvements.

    We need points after thousands…

    You need PHP.

    We just would like to have this handled in the right way by Expression Engine.

    EE doesn’t do this out of the box. Look into PHP’s sprintf() function.

  • #4 / Oct 29, 2008 2:02pm

    Per

    45 posts

    Hi Robin,

    We have been staring at these php codes before and are doing it right now again. The page you mentioned (http://us3.php.net/number_format) gives this clue for dutch annotation by ‘kolnedra’:

    =====

    <?
    // geld(123) >>> 123
    // geld(123456) >>> 1.234.567
    function geld($nm) {
    for ($done=strlen($nm); $done > 3;$done -= 3) {
    $returnNum = ".".substr($nm,$done-3,3).$returnNum;
    }
      return substr($nm,0,$done).$returnNum;
    }
    ?>

    =====

    In our template we call the prize with {vraagprijs}

    Such a price would be filled in as: 100000 in the admin, and we want it to be displayed as 100.000 on the webpage.

    Where do we put this code? In the template? Within the accolades besides vraagprijs?

    Change ‘geld’ (= Dutch for money) for ‘vraagprijs’?

    We tried different things, all result in code being displayed in the webpage.

    Can you please give a hint were or how to make the connection with {vraagprijs}
    and the parsing code.

    Thanks,
    Piedro

  • #5 / Oct 29, 2008 2:16pm

    Per

    45 posts

    Hi Ingmar,

    The building of this site has begun more then a year ago and put on hold for a year. Only recently we were asked to finish the job. That is great. So we picked up where we got stuck a year ago. This prize thing. We will certainly update the installation, but not before we get things working technically. And showing prizes correct and easy.

    We hope you can help us out here without having to take php courses. It is only points between Dutch prizes.

    Thanks.

  • #6 / Oct 29, 2008 2:20pm

    Robin Sowell

    13255 posts

    I’d likely roll it into a plugin.  But to test- in order to use php in a template, you’ll need to specifically turn php on for that template.  And for what you want to do- set it to parse on output (which is the default).  So- when you are on the Template Group page- click ‘Preferences’ for that group- you can set the php preference for each template there.

    Then- test out the function by hard coding it.

    <?
    
    function geld($nm) {
      for ($done=strlen($nm); $done > 3;$done -= 3) {
          $returnNum = ”.”.substr($nm,$done-3,3).$returnNum;
      }
      return substr($nm,0,$done).$returnNum;
    }
    
    echo geld(123456);
    ?>

    Does that output the number formated like you need?  If so- then basically?  Use the custom field instead of the hard coded 123456 and see if that works.

    Make sense?

  • #7 / Oct 29, 2008 6:01pm

    Ingmar

    29245 posts

    Piedro, it’s really simple. PHP has a function named number_format() that does all that for you:

    <?php $number = "100000"; 
    echo number_format($number, 0, ',', '.');
    ?>

    0 being the number of decimals, followed by the decimal separator, followed by the group separator. Makes sense?

  • #8 / Oct 30, 2008 10:44am

    Per

    45 posts

    Hi Robin and Ingmar,

    Thank you for your advice.

    First I tried to set up a new plugin. This did not work. The complete list of plugins became empty 😊!

    Then I tried setting the template to allow php. This made a little mess of the page.

    Then I decided to upgrade first to 1.6.5 from 1.6.1. Completed.

    Then I set up the php-script Ingmar gave (and now succesfully allowed php on the template):


    <?php $number = “100000”;
    echo number_format($number, 0, ‘,’, ‘.’);
    ?>


    We changed it to:


    €  <?php $number = “{vraagprijs}”;
    echo number_format($number, 0,’,’,’.’);
    ?>,-

    and is showing up like this:
    € 100.000,-


    This worked right away!

    Thank you very much for your fast support again!

    Piedro

  • #9 / Oct 30, 2008 11:57am

    Ingmar

    29245 posts

    Very good, I am glad to hear it’s working for you.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases