<p>How about something like:</p>

<pre><code>&amp;pound;{{ 1000.00 | number_format(2,'.',',') | replace({".00" : ""}) }}
</code></pre>

<p>gives:</p>

<p>£1,000</p>

<p>Got a similar idea from <a href="https://craftcms.stackexchange.com/questions/566/how-would-i-omit-zero-value-decimals-in-a-number-format">How would I omit zero value decimals in a number format?</a>.</p>

CC BY-SA 3.0
2015-09-30T20:07:09.123Z
2015-09-30T20:07:09.123Z
2017-04-13T12:51:00.200Z
mattl
<p>Just for future reference, Craft 3 is a little different with the currency filter.</p>

<pre><code>{{ entry.price|currency('CAD', stripZeros = true) }}
</code></pre>

CC BY-SA 3.0
2018-04-02T12:59:25.923Z
Would you mind explaining what makes your answer different than Brandons?
Robin Schambach
CC BY-SA 3.0
2018-04-02T22:44:11.283Z
@RobinSchambach I tried using this one ('CAD', true) in my new Craft 3 build and was getting an error. So you have to use this ('CAD', stripZeros = true) for it to work in Craft 3
mateostabio
CC BY-SA 3.0
2018-04-02T12:50:39.000Z
2018-04-02T12:50:39.000Z
mateostabio
<p>Well I've got this working with:</p>

<pre><code>{% set decimal = entry.priceFrom|reverse|slice(1,2) %}

{% if decimal == "0" %}{{ entry.priceFrom|number_format(0,'.',',') }}{% else %}{{ entry.priceFrom|number_format(2,'.',',') }}{% endif %}
</code></pre>

<p>Basically I'm reversing the string so I can check for a zero at the end (or not). It's fairly clean, but if anyone can improve on it I'd love to hear.</p>

CC BY-SA 3.0
2015-09-30T17:11:14.247Z
2015-09-30T17:11:14.247Z
Ian Ebden
<p>Craft comes with a <a href="http://buildwithcraft.com/docs/templating/filters#currency">currency</a> filter that makes this pretty easy – you don’t even need the <code>&amp;pound;</code>:</p>

<pre><code>{{ entry.priceFrom|currency('GBP', true) }}
</code></pre>

<p>The <code>'GBP'</code> establishes the currency (so the price is prefixed with <code>£</code>), and passing <code>true</code> to the second argument tells Craft to strip out the cents from the formatted string if there aren’t any (so <code>£100</code> instead of <code>£100.00</code>).</p>

CC BY-SA 3.0
2015-10-06T09:16:18.893Z
Wow, great thanks.
Ian Ebden
CC BY-SA 3.0
2015-10-01T22:21:38.453Z
2015-10-01T22:21:38.453Z
Brandon Kelly
<p>I'm outputting prices in a channel with a little formatting like so:</p>

<pre><code>&amp;pound;{{ entry.priceFrom|number_format(2,'.',',') }}
</code></pre>

<p>Gives me £1,000.00 or £99.99 etc... However client isn't a fan of the double zeros (e.g. £100.00) and would prefer such prices to show up as £100 – only showing decimal numbers if they're not "00".</p>

<p>I was working on some kind of preprocessing/condition here but it seems long-winded, and wondered if anyone has a neat solution?</p>

<format><number>
Price Formatting
# Price Formatting

(Asked by: username_0 on 2015-09-30)

I'm outputting prices in a channel with a little formatting like so:
£{{ entry.priceFrom|number_format(2,'.',',') }}

Gives me £1,000.00 or £99.99 etc... However client isn't a fan of the double zeros (e.g. £100.00) and would prefer such prices to show up as £100 – only showing decimal numbers if they're not "00".
I was working on some kind of preprocessing/condition here but it seems long-winded, and wondered if anyone has a neat solution?

**Tags:** format, number


---

## 4 answers

### Answer by username_4 on 2015-10-01. Score: 12 | Accepted answer

Craft comes with a currency filter that makes this pretty easy – you don’t even need the £:
{{ entry.priceFrom|currency('GBP', true) }}

The 'GBP' establishes the currency (so the price is prefixed with £), and passing true to the second argument tells Craft to strip out the cents from the formatted string if there aren’t any (so £100 instead of £100.00).

> **Comments:**
> **username_0**: Wow, great thanks.  

---

### Answer by username_1 on 2015-09-30. Score: 3

How about something like:
£{{ 1000.00 | number_format(2,'.',',') | replace({".00" : ""}) }}

gives:
£1,000
Got a similar idea from How would I omit zero value decimals in a number format?.


---

### Answer by username_2 on 2018-04-02. Score: 2

Just for future reference, Craft 3 is a little different with the currency filter.
{{ entry.price|currency('CAD', stripZeros = true) }}

> **Comments:**
> **username_3**: Would you mind explaining what makes your answer different than Brandons?  
> **username_2**: @RobinSchambach I tried using this one ('CAD', true) in my new Craft 3 build and was getting an error. So you have to use this ('CAD', stripZeros = true) for it to work in Craft 3  

---

### Answer by username_0 on 2015-09-30. Score: 1

Well I've got this working with:
{% set decimal = entry.priceFrom|reverse|slice(1,2) %}

{% if decimal == "0" %}{{ entry.priceFrom|number_format(0,'.',',') }}{% else %}{{ entry.priceFrom|number_format(2,'.',',') }}{% endif %}

Basically I'm reversing the string so I can check for a zero at the end (or not). It's fairly clean, but if anyone can improve on it I'd love to hear.


---

