<p>Craft's number fields aren't represented by strings. You can check that by putting a debug statement like this in one of your templates:</p>
<pre class="lang-twig prettyprint-override"><code>{% dd product.myNumberField %}
</code></pre>
<p>If you get something like <code>'3.141'</code>, that's a string. <code>3</code> is an integer and <code>3.141</code> is a float.</p>
<p>For number fields, this will give you an integer or float, depending on whether the field value is an integer or a fraction.</p>
<p>If you see both commas and dots in the number field in the CMS, that's the local input format at play. The value will be interpreted based on the user's <strong>Formatting Locale</strong> set in their account preferences. For example, if you set this to English, commas are treated as thousands separator, and the dot as radix/decimal separator. If you set it to German, you get the inverse behaviour (we're weird that way …)</p>
<p>If you switch between languages in your developer account, it takes some getting used to. But your authors just need to set their account to their preferred language and remember to use the convention of that language, then it will work fine.</p>

CC BY-SA 4.0
2024-02-12T09:37:50.597Z
My issue is that the fields themselves are text fields with an attribute inputmode="numeric". I want to do calculations with JS by reading the value of the fields. That means I can't use the Craft helpers to translate text value to the real number. With a number field this is not an issue since you always get the correct number formatting for calculations in JS. With the text fields in Craft I need to manually convert the comma's to dots in order to be able to do some calculations.
Matthias
CC BY-SA 4.0
2024-02-11T17:43:50.180Z
2024-02-11T17:43:50.180Z
MoritzLost
<p>I am building a small price calculator in the Product type entry for Craft Commerce by building a custom plugin.
This plugin executes my javascript file.</p>
<p>The issue I am encountering is that I need to do calculations with the numbers fields that are present in the form. Since they are not real number fields users are allowed to use both comma's and points as separator for decimals.</p>
<p>So my issue is that I never know if the comma or the point is the decimal separator.</p>
<p>What could fix this issue?
Can I force Craft to use real number fields?</p>

<plugin-craftcommerce><number>
Why are number fields actually text fields in Craft?
# Why are number fields actually text fields in Craft?

(Asked by: username_0 on 2024-02-09)

I am building a small price calculator in the Product type entry for Craft Commerce by building a custom plugin.
This plugin executes my javascript file.

The issue I am encountering is that I need to do calculations with the numbers fields that are present in the form. Since they are not real number fields users are allowed to use both comma's and points as separator for decimals.

So my issue is that I never know if the comma or the point is the decimal separator.

What could fix this issue?
Can I force Craft to use real number fields?

**Tags:** plugin-craftcommerce, number

---

## 1 answers

### Answer by username_1 on 2024-02-11. Score: 0

Craft's number fields aren't represented by strings. You can check that by putting a debug statement like this in one of your templates:
{% dd product.myNumberField %}

If you get something like '3.141', that's a string. 3 is an integer and 3.141 is a float.
For number fields, this will give you an integer or float, depending on whether the field value is an integer or a fraction.
If you see both commas and dots in the number field in the CMS, that's the local input format at play. The value will be interpreted based on the user's Formatting Locale set in their account preferences. For example, if you set this to English, commas are treated as thousands separator, and the dot as radix/decimal separator. If you set it to German, you get the inverse behaviour (we're weird that way …)
If you switch between languages in your developer account, it takes some getting used to. But your authors just need to set their account to their preferred language and remember to use the convention of that language, then it will work fine.

> **Comments:**
> **username_0**: My issue is that the fields themselves are text fields with an attribute inputmode="numeric". I want to do calculations with JS by reading the value of the fields. That means I can't use the Craft helpers to translate text value to the real number. With a number field this is not an issue since you always get the correct number formatting for calculations in JS. With the text fields in Craft I need to manually convert the comma's to dots in order to be able to do some calculations.  

---

