Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9225573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:36:42+00:00 2026-06-18T04:36:42+00:00

I have a division in twig. Sometimes, the result can be with decimals and

  • 0

I have a division in twig. Sometimes, the result can be with decimals and i need to have always a rounded up result.

Ex.

7 / 2 = 3.5

I would like to have

7 / 2 = 4

I know how to use floor in twig:

7 / 2 | floor = 3

But this is rounding to the down digit, not to the upper one.

I know also that i can use number_format

7 / 2 | number_format(0, '.', ',') = 3

So this will also take the down digit.

Any idea on how to tell twig to take the upper digit ?

This can be done in a controller (Symfony), but I am looking for the twig version.

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:36:44+00:00Added an answer on June 18, 2026 at 4:36 am

    Update

    On versions 1.15.0+, round filter is available.

    {{ (7 / 2)|round(1, 'ceil') }}
    

    https://twig.symfony.com/doc/3.x/filters/round.html


    You can extend twig and write your custom functions as it is described here

    And it will be something like this:

    <?php
    // src/Acme/DemoBundle/Twig/AcmeExtension.php
    namespace Acme\DemoBundle\Twig;
    
    class AcmeExtension extends \Twig_Extension
    {
        public function getFilters()
        {
            return array(
                'ceil' => new \Twig_Filter_Method($this, 'ceil'),
            );
        }
    
        public function ceil($number)
        {
            return ceil($number);
        }
    
        public function getName()
        {
            return 'acme_extension';
        }
    }
    

    So you can you use it in twig:

    (7 / 2) | ceil
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have trouble figuring out why a simple division like this one always returns
Does anyone know how I can update the style attribute of a division using
I have separated my screen into 4.I like to use the same static variable
I have the following function that implements division without the use of a modulus
I'm using php,html,javascript,mysql. My functionality goes like this. I have a division made in
I have the following division that I need to do often: int index =
The system rules: Departments can have 0 to many divisions. A division must belong
I have 2 dropdownlists, the second (department) cascades from the first (division). I use
I have a simple Xml Node that I need to recreate <Division ID=123>Division Name</Division>
I have a division operation inside a cycle that repeats many times. It so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.