Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

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

Displaying Currency Nicely


Reply


5 Posts   1340 Views

Avatar
mrsteveheyes

Community Member, 15 Posts

31 August 2011 at 10:01pm

Edited: 31/08/2011 10:02pm

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

Avatar
martimiz

Forum Moderator, 1132 Posts

31 August 2011 at 11:54pm

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

Avatar
mrsteveheyes

Community Member, 15 Posts

2 September 2011 at 10:31pm

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

Avatar
mrsteveheyes

Community Member, 15 Posts

2 September 2011 at 11:20pm

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

Avatar
CHD

Community Member, 218 Posts

5 March 2012 at 9:10am

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