[Circuits] Round up when dividing?

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
Post Reply
TheG_Ghaladron
Manual Inserter
Manual Inserter
Posts: 1
Joined: Fri Feb 04, 2022 12:39 am
Contact:

[Circuits] Round up when dividing?

Post by TheG_Ghaladron »

Title says it all really. The arithmetic combinator rounds down when it divides, but I need it to always round up instead. What's the most compact way to do this? My first thought was add 1, but that doesn't work if the division gives an integer.

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: [Circuits] Round up when dividing?

Post by DaveMcW »

Add (Divisor - 1) before you do the division.

DasNasu
Burner Inserter
Burner Inserter
Posts: 6
Joined: Sun Jan 13, 2019 4:55 pm
Contact:

Re: [Circuits] Round up when dividing?

Post by DasNasu »

Sorry for necroposting but either i missunderstand something or the answer is wrong. simple example:

10 / 9 with round up would be 2, because 10/9 = 1.111...... with rounding up it gives 2. putting this in an arithmetic still outputs 1 because is rounds down after calculation
Every good story ends with System.exit(0);

User avatar
Stringweasel
Filter Inserter
Filter Inserter
Posts: 315
Joined: Thu Apr 27, 2017 8:22 pm
Contact:

Re: [Circuits] Round up when dividing?

Post by Stringweasel »

DasNasu wrote:
Tue Jun 13, 2023 5:22 am
Sorry for necroposting but either i missunderstand something or the answer is wrong. simple example:
Seems correct to me

(10 + (9-1)) / 9 = 18 / 9 = 2

And if your round 2 down, it's still 2. If it's not working for you in-game then there might be a problem in how you used it.
Alt-F4 Author | Factorio Modder
Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby

Post Reply

Return to “Gameplay Help”