Jump to:

23493 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Displaying Currency Nicely

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1177 Views
  • mrsteveheyes
    Avatar
    Community Member
    15 Posts

    Displaying Currency Nicely Link to this post

    Hi there. I am using the currency object as one of the fields in an object on Silverstripe. However; whenever I display it in the temaple it has four digits after the decimal point. I just wondered if there is anyway of stopping it and it only showing two. Below is an example of the code:

    <% control Courses %>
       <tr>
          <td class="first"><a href="{$Top.BaseHref}{$Top.URLSegment}/{$URLSegment}">$Title</a></td>
          <td>$Duration</td>
          <td class="highlight">{$PriceCurrency}{$PriceAmount}
          </td>
          <td class="last"><a class="date-link" href="/booking/course/{$ID}">Find Dates</a></td>
       </tr>
    <% end_control %>

    <tr>
       <td class="first"><a href="{Link Removed}">Fire Safety Course</a></td>
       <td></td>
       <td class="highlight">£0.0000</td>
       <td class="last"><a class="date-link" href="/booking/course/2">Find Dates</a></td>
    </tr>

    Hope someone can help.

    Cheers,
    Steve

  • martimiz
    Avatar
    Forum Moderator
    1086 Posts

    Re: Displaying Currency Nicely Link to this post

    You could use $PriceCurrency.Nice in your template...

  • mrsteveheyes
    Avatar
    Community Member
    15 Posts

    Re: Displaying Currency Nicely Link to this post

    Thanks martimiz but it didn't work. It didn't show up anything if I did that.

    Other options I've tried that didn't work are:

    $PriceCurrency.Format
    $PriceCurrency.Currency
    $PriceCurrency.Decimal

    Anyone got any other suggestions?

    Cheers,
    Steve

  • mrsteveheyes
    Avatar
    Community Member
    15 Posts

    Re: Displaying Currency Nicely Link to this post

    I figured it out! We we're nearly there with Nice. But it should of been attached to the object, not the string of it. So to get it to work I used:

    $Price.Nice

    And it worked

    Cheers,
    Steve

  • CHD
    Avatar
    Community Member
    218 Posts

    Re: Displaying Currency Nicely Link to this post

    For anybody having problems getting currency symbols to display with .Nice - use the code for the symbol:
    Currency::setCurrencySymbol('&pound;');

    1177 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.