# [Solved] How do I get an int() without rounding up?

Get help using Construct 2

### » Wed Mar 11, 2015 12:02 am

int(-32.7023072454) = -33

floor(-32.7023072454) also = -33

How can I get just the -32 integer part?

Thanks
Last edited by locohost on Thu Mar 12, 2015 10:54 am, edited 1 time in total.
B
13
S
4
Posts: 280
Reputation: 1,566

### » Wed Mar 11, 2015 12:45 am

B
57
S
23
G
7
Posts: 1,427
Reputation: 10,508

### » Wed Mar 11, 2015 1:09 am

To work with positive and negative values: the integer of a variable Var = int(abs(Var)) * abs(Var) / Var
B
62
S
15
G
56
Posts: 2,138
Reputation: 36,348

### » Wed Mar 11, 2015 12:27 pm

korbaach wrote:ceil(-32.7023072454) = -32

https://www.scirra.com/tutorials/77/nat ... onstruct-2

Umm, thanks, but click the link you provided...

Ceil(number) - Round a number up (eg. ceil(6.1) returns 7).
B
13
S
4
Posts: 280
Reputation: 1,566

### » Wed Mar 11, 2015 4:03 pm

Yes..Ceil(number) - Round a number up.. ceil(-32.7023072454) = -32 ...................... (-32 > -33 )
B
57
S
23
G
7
Posts: 1,427
Reputation: 10,508

### » Wed Mar 11, 2015 4:42 pm

int(), floor(), ceil() all round up. Not sure why.

For now I'm using this string parser/converting/thing, calling it "Trunc". It's working...

C2TruncateFunction.PNG
You do not have the required permissions to view the files attached to this post.
B
13
S
4
Posts: 280
Reputation: 1,566

### » Wed Mar 11, 2015 6:16 pm

int() and floor() round down to negative infinity. -33 is less than -32.7023072454 so that's down.
int(-32.7023072454) = -33
floor(-32.7023072454) = -33

ceil() rounds up to positive infinity.
int(-32.7023072454) = -32

round() rounds to whatever direction is closer.
round(-32.7023072454) = -33
B
82
S
26
G
62
Posts: 4,824
Reputation: 45,188

### » Wed Mar 11, 2015 6:30 pm

Hmmm... Ok you're right. Perhaps using the negative number in the OP is making this harder to understand
B
13
S
4
Posts: 280
Reputation: 1,566

### » Thu Mar 12, 2015 10:59 am

Yeah you guys are right, it's easy. I used a ternary operator to basically perform a trunc()...

Code: Select all
` decimalAngle = ( decimalAngle < 0 ) ? ceil(decimalAngle) : floor(decimalAngle)`

This works. Thank you everyone!
B
13
S
4
Posts: 280
Reputation: 1,566