<p>Fetching the field and outputting the following should work.</p>
<pre><code>{% set field = craft.app.fields.getFieldByHandle('my-field-handle') %}
{{ field.prefix }}
{{ entry.rentalPrice }}
{{ field.suffix }}
{{ field.previewCurrency }}
</code></pre>
<p>Class reference: <a href="https://docs.craftcms.com/api/v5/craft-fields-number.html#public-properties" rel="nofollow noreferrer">https://docs.craftcms.com/api/v5/craft-fields-number.html#public-properties</a></p>

CC BY-SA 4.0
2024-04-08T07:38:31.297Z
Thank you. Unfortunately, for me it doesn't work. I am using CraftCMS 5.x. I get an error: **Twig Runtime Error – Twig\Error\RuntimeError / Impossible to access an attribute ("prefix") on a integer variable ("175"). / Impossible to access an attribute ("suffix") on a integer variable ("175"). / Impossible to access an attribute ("previewCurrency") on a integer variable ("175").** Even better would be to have just one variable that will show the field value including prefix, suffix and currency.
flip
CC BY-SA 4.0
2024-04-08T08:55:25.890Z
I also tried **{{ entry.rentalPrice.currency ?? null }}** which neither produces an error nor shows any data. I have set a value for prefix, suffix and currency so it shouldn't be empty.
flip
CC BY-SA 4.0
2024-04-08T18:47:14.167Z
Oh right, I forgot that the normalised value is returned. I updated my answer to fetch the field itself.
Ben Croker
CC BY-SA 4.0
2024-04-09T11:32:11.510Z
Thank you! It works but it is a lot of code for one field. According to this documentation it should be **craft.app.fields.getFieldByHandle** instead of **craft.app.fields.fieldByHandle**: https://craftcms.com/docs/5.x/reference/twig/global-variables.html
flip
CC BY-SA 4.0
2024-04-10T00:36:34.140Z
Both work, but I updated my answer to match the docs. It’s really just one line of code to get the field. The rest is to output it in whatever format you want.
Ben Croker
CC BY-SA 4.0
2024-04-06T16:46:21.480Z
2024-04-10T00:35:45.877Z
2024-04-10T00:35:45.877Z
Ben Croker
<p>I have added a number field with prefix, suffix and currency symbol:
<a href="https://i.sstatic.net/8Fv1R.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/8Fv1R.png" alt="enter image description here" /></a></p>
<p>How can I add a variable to a template which shows the number with prefix, suffix and currency? I tried the following which didn't work:
{{ entry.rentalPrice|money }}</p>
<p>I couldn't find the information in the documentation: <a href="https://craftcms.com/docs/5.x/reference/field-types/number.html" rel="nofollow noreferrer">https://craftcms.com/docs/5.x/reference/field-types/number.html</a></p>

<templating><field><variable><number>
Add number variable to template with prefix, suffix and currency
# Add number variable to template with prefix, suffix and currency

(Asked by: username_0 on 2024-04-06)

I have added a number field with prefix, suffix and currency symbol:
[![enter image description here](https://i.sstatic.net/8Fv1R.png)](https://i.sstatic.net/8Fv1R.png)

How can I add a variable to a template which shows the number with prefix, suffix and currency? I tried the following which didn't work:
{{ entry.rentalPrice|money }}

I couldn't find the information in the documentation: <https://craftcms.com/docs/5.x/reference/field-types/number.html>

**Tags:** templating, field, variable, number

---

## 1 answers

### Answer by username_1 on 2024-04-06. Score: 2 | Accepted answer

Fetching the field and outputting the following should work.
{% set field = craft.app.fields.getFieldByHandle('my-field-handle') %}
{{ field.prefix }}
{{ entry.rentalPrice }}
{{ field.suffix }}
{{ field.previewCurrency }}

Class reference: https://docs.craftcms.com/api/v5/craft-fields-number.html#public-properties

> **Comments:**
> **username_0**: Thank you. Unfortunately, for me it doesn't work. I am using CraftCMS 5.x. I get an error: **Twig Runtime Error – Twig\Error\RuntimeError / Impossible to access an attribute ("prefix") on a integer variable ("175"). / Impossible to access an attribute ("suffix") on a integer variable ("175"). / Impossible to access an attribute ("previewCurrency") on a integer variable ("175").** Even better would be to have just one variable that will show the field value including prefix, suffix and currency.  
> **username_0**: I also tried **{{ entry.rentalPrice.currency ?? null }}** which neither produces an error nor shows any data. I have set a value for prefix, suffix and currency so it shouldn't be empty.  
> **username_1**: Oh right, I forgot that the normalised value is returned. I updated my answer to fetch the field itself.  
> **username_0**: Thank you! It works but it is a lot of code for one field. According to this documentation it should be **craft.app.fields.getFieldByHandle** instead of **craft.app.fields.fieldByHandle**: https://craftcms.com/docs/5.x/reference/twig/global-variables.html  
> **username_1**: Both work, but I updated my answer to match the docs. It’s really just one line of code to get the field. The rest is to output it in whatever format you want.  

---

