Skip to main content
9 votes

How would I omit zero value decimals in a number format?

multiply by 1: {{ 12.50 * 1 }} == 12.5 {{ 12.0 * 1 }} == 12
Fernando's user avatar
5 votes

Math with numeric values derived from a dropdown field

Have you tried subhead.hLevel.value?
Oli's user avatar
  • 7,495
3 votes
Accepted

Non-numeric characters in number field producing errors

Just tested this on a local Craft3 setup and here's what I discovered... If the decimal points setting on the number field is set to 0, adding text in the number field will display the pretty errors ...
Jalen Davenport's user avatar
  • 3,045
3 votes

Sum up number fields in the loop

Hmm... hard to tell because I can’t know what your expected result would be. But if I had to guess then you might be looking for just this: {% if aPrice %} {% set thisMonthEarning = ...
carlcs's user avatar
  • 36.3k
3 votes
Accepted

Calculating a score based on a drop down field value

When working with a dropdown in Twig, it's important to remember that you're dealing with an object (not a simple string). This is an object: {{ entry.myDropdown }} It's easy to forget, however, ...
Lindsey D's user avatar
  • 24k
3 votes

How would I omit zero value decimals in a number format?

This limits it to 4 places and trims only trailing zeroes. {{ item.width | number_format(4) | trim("0", "right") | trim(".") }}
Andri S's user avatar
  • 31
2 votes

How would I omit zero value decimals in a number format?

You can add a filter to twig (adding filters) And make it sound like this: $filter = new Twig_SimpleFilter('roundIf', function ($val) { return number_format($val, (int)$val == $val ? 0 : 2, ',', ...
Rafał Mnich's user avatar
2 votes

Price Formatting

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

Getting an zero index and count for an entry list

There's an easier way... Twig has a built-in variable in for-loops called loop, which has loop.index and loop.index0 properties which output exactly what you're looking for: https://twig.symfony.com/...
James Smith's user avatar
  • 5,344
2 votes
Accepted

Sum up number fields in the loop

Try this: {# Get this month's data #} {% set thisMonthStatistic = orders.postDate('and', '>= ' ~ firstDayOfMonth, '<= ' ~ lastDayOfMonth) %} {# We must set variable "0" and pass it in for the ...
Marion Newlevant's user avatar
2 votes
Accepted

Add number variable to template with prefix, suffix and currency

Fetching the field and outputting the following should work. {% set field = craft.app.fields.getFieldByHandle('my-field-handle') %} {{ field.prefix }} {{ entry.rentalPrice }} {{ field.suffix }} {{ ...
Ben Croker's user avatar
  • 7,536
2 votes

start ordered list with number 2

You can use the start attribute to control the start number of an ordered list: <ol start="2"> <li>Item 1</li> <li>Item 2</li> </ol> Depending on ...
MoritzLost's user avatar
  • 11.5k
1 vote

Getting all images urls and help with numbers field

It looks like you have 2 questions here? 1- why not run them through a loop? it will then only display the amount of images you have. eg; {% for images in entry.car_photos.all() %} <div class="...
Mark Lloyd's user avatar
1 vote

Getting an zero index and count for an entry list

I have managed to figure it out. I will use the following and it seems to work fine {% set indexCounter = ( counter | default(0) ) %} {% set counter = ( counter | default(0) ) + 1 %} Hope this can ...
Adam's user avatar
  • 255
1 vote
Accepted

Feed Me import from CSV ignores decimal point

With the help of the Craft Support Team, i solved this problem for me. Two ways to solve this: Change Number field to text field. Change Language under users/user/preferences/language from Deutsch to ...
TomS's user avatar
  • 213
1 vote

Number field when empty and value=0

Twig's is not null should work for this. Assuming you have a Number field called number and you're looping through a list of entries, something like this should work: {% for entry in entries if ...
Brad Bell's user avatar
  • 67.5k
1 vote

Replace quotes in an array

So it seems that even although the Craft field is set to number it doesn't actually define a number. I changed the field from a regular Craft table field to a Super Table field and my {{ donutData|...
Steven Grant's user avatar
  • 1,855
1 vote

Searching Number Field To See If It Falls In A Range

Remember: all parameters in your Query are set to null by default. They won't be parsed into an SQL statement until they have a valid value (not "", not NULL not 0) so you can just pass null values. {...
Robin Schambach's user avatar
1 vote
Accepted

Display children's order numbers

If you're getting all the descendants in the for loop, you can use loop to get the index of the current iteration: {% for chapter in entry.descendants %} <div class="part"><span>Part {...
André Elvan's user avatar
  • 7,288
1 vote

How would I omit zero value decimals in a number format?

{% set test1 = "12.05" %} {% set test1 = test1 // 1 %} The output will be 12
Robert Saylor's user avatar
1 vote

How would I omit zero value decimals in a number format?

If you don't want to pipe that much, you should be able to use sprintf and do something like this: {{ '%02g' | format(item.width) }} https://twig.symfony.com/doc/2.x/filters/format.html https://www....
Erik Weber's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible