question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Round _up_ math.divided_by?

See original GitHub issue

Team,

Is it possible to do a math.divided_by and round UP the result?

Now: {{ 25 | math.divided_by 2 }} = 12.5 so it will return 12

The goal is to “round up” the 12.5 to 13 instead of down to 12.

IF you could check if the start number is_odd or is_even, then you could

  • if_odd: add 1 to 25 --> 26 --> /2 = 13
  • if_even: --> /2

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
xoofxcommented, Dec 22, 2020

hm, in some cases, number will not round correctly with floating point numbers. You can try to use a custom function that wraps double.Round(Double, MidpointRounding) using MidpointRounding.AwayFromZero

I can add maybe later a function math.round_away_from_zero but it won’t solve all issues as explained in the doc linked.

1reaction
xoofxcommented, Dec 22, 2020

You can probably use something like {{ (25 / 2) + 0.5 | math.round }}

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to round up the result of integer division? - java
For C# the solution is to cast the values to a double (as Math.Ceiling takes a double): int nPages = (int)Math.Ceiling((double)nItems ...
Read more >
How to round up the answer of an integer division?
If you want to round up instead, a quick way is, as the top comment says, just to add denominator - 1 to...
Read more >
Decimal Rounding and Division | CK-12 Foundation
If the number is equal to or greater than 5, round the number up. Round 2.1046891425 to the nearest hundredths place. The number...
Read more >
Rounding Numbers - Kids Math
When the number you are rounding is between 0-4, you round down to the next lowest number. When the number is 5-9, you...
Read more >
Round up when Dividing numbers - Power Platform Community
Hello Teams, I'm using 'Div' function to divide a number by 30 and I want to round up the result. For example, 139/30...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found