Answers.Body: <p>I got the Craft percentage filter to work by enclosing the calculation in parens, like this:</p>
  <pre><code>{{ (var1 / var2) | percentage }}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-13T23:03:07.603Z
Answers.LastActivityDate: 2021-02-13T23:03:07.603Z
Answers.UserDisplayName: Roi Agneta
Answers.Body: <p>You're getting the error because of Twig's <a href="https://twig.symfony.com/doc/3.x/templates.html#expressions" rel="nofollow noreferrer">operator precedence</a>. Filters take priority over math.</p>
  <p>So basically Twig was trying change <code>var2</code> to a percentage first instead of using the results of the math expression first, ie:</p>
  <p><code>{{ var1 / (var2 | percentage) }}</code></p>
  <p>Generally this behavior is usually what you want but sometimes there's edge cases where it doesn't work out. As you figured out, putting parenthesis around expressions to group them is never a bad idea especially when filters are involved.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-18T16:31:09.353Z
Answers.Text: Thanks for the explanation!
Answers.UserDisplayName: Roi Agneta
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-20T19:31:10.287Z
Answers.Text: @RoiAgneta feel free to accept this one (or yours for matter) as the accepted answer.
Answers.UserDisplayName: RitterKnight
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-15T21:14:26.880Z
Answers.LastActivityDate: 2021-02-15T21:14:26.880Z
Answers.UserDisplayName: RitterKnight
Body: <p>Twig docs include a format_number filter, as of ver 2.12</p>
  <p>My install shows Twig at ver 2.12.5, so should work, but throws a Twig Syntax Error: Unknown &quot;format_percent_number&quot; filter.</p>
  <p>This started with not being able to use the Craft &quot;percentage&quot; filter because I was doing this:</p>
  <pre><code>{{ var1 / var2 | percentage }}
  </code></pre>
  <p>That filter fails because 'var1 / var2' returns a number without a leading zero and Craft does not like that.</p>
  <p>So, two issues:</p>
  <ol>
  <li>the Twig filter format_number not work</li>
  <li>any thoughts on how to get around the Craft percentage filter issue</li>
  </ol>
  <p>Thanks!</p>
  
Tags: <templating><filter>
Title: Twig Format Number Filter not working
ThreadText: # Twig Format Number Filter not working
  
  (Asked by: username_0 on 2021-02-13)
  
  Twig docs include a format\_number filter, as of ver 2.12
  
  My install shows Twig at ver 2.12.5, so should work, but throws a Twig Syntax Error: Unknown "format\_percent\_number" filter.
  
  This started with not being able to use the Craft "percentage" filter because I was doing this:
  
  ```
  {{ var1 / var2 | percentage }}
  
  ```
  
  That filter fails because 'var1 / var2' returns a number without a leading zero and Craft does not like that.
  
  So, two issues:
  
  1. the Twig filter format\_number not work
  2. any thoughts on how to get around the Craft percentage filter issue
  
  Thanks!
  
  **Tags:** templating, filter
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2021-02-13. Score: 1 | Accepted answer
  
  I got the Craft percentage filter to work by enclosing the calculation in parens, like this:
  
  ```
  {{ (var1 / var2) | percentage }}
  
  ```
  
  
  ---
  
  ### Answer by username_1 on 2021-02-15. Score: 2
  
  You're getting the error because of Twig's [operator precedence](https://twig.symfony.com/doc/3.x/templates.html#expressions). Filters take priority over math.
  
  So basically Twig was trying change `var2` to a percentage first instead of using the results of the math expression first, ie:
  
  `{{ var1 / (var2 | percentage) }}`
  
  Generally this behavior is usually what you want but sometimes there's edge cases where it doesn't work out. As you figured out, putting parenthesis around expressions to group them is never a bad idea especially when filters are involved.
  
  > **Comments:**
  > **username_0**: Thanks for the explanation!  
  > **username_1**: @username_0 feel free to accept this one (or yours for matter) as the accepted answer.  
  
  ---
  
  