How do you set the rounding for integers?
In FreeBasic, the following code:
Will print:
3
3
4
Iin Cerberus, the following code:
Will print:
3
3
3
I want the last print statement to output a 4 in Cerberus.
I know about the Ceil and Floor functions, but the use of those assumes that you know ahead of time what the variable value is and how you want to change it.
And you have to use floats.
For example:
The above code will print:
3
y =3.2
Ceil = 4
Floor = 3
y =3.8
Ceil = 4
Floor = 3
To get what I am looking for I would need to apply both functions Ceil and Floor to the variable y, but I would have to know, as in this example,
if y > 3.5 or y < 3.5. Of course this is just an example and we can see the variable's value and pick the correct function.
But, in real code, the variable could have its assignment be a complex expression e.g. y = mousex()/sin * PI
Is there some way to have an integer round up to the next integer value when it is greater than half way to the next integer?
In FreeBasic, the following code:
Cerberus:
#include "fbgfx.bi"
Using FB
Dim as integer x
x = 3
Print x
x = 3.2
Print x
x = 3.8
Print x
Do
Loop Until Multikey(SC_ESCAPE)
3
3
4
Iin Cerberus, the following code:
Cerberus:
Function Main()
New Game()
End
Class Game Extends App
Method OnCreate()
Local x:Int
x = 3
Print x
x = 3.2
Print x
x = 3.8
Print x
End
End
3
3
3
I want the last print statement to output a 4 in Cerberus.
I know about the Ceil and Floor functions, but the use of those assumes that you know ahead of time what the variable value is and how you want to change it.
And you have to use floats.
For example:
Cerberus:
Import mojo
Function Main()
New Game()
End
Class Game Extends App
Method OnCreate()
Local y:Float
y = 3
Print y
y = 3.2
Print "y =" + y
Print "Ceil(y) = " + Ceil(y)
Print "Floor(y) = " + Floor(y)
y = 3.8
Print "y =" + y
Print "Ceil(y) = " + Ceil(y)
Print "Floor(y) = " + Floor(y)
End
End
3
y =3.2
Ceil = 4
Floor = 3
y =3.8
Ceil = 4
Floor = 3
To get what I am looking for I would need to apply both functions Ceil and Floor to the variable y, but I would have to know, as in this example,
if y > 3.5 or y < 3.5. Of course this is just an example and we can see the variable's value and pick the correct function.
But, in real code, the variable could have its assignment be a complex expression e.g. y = mousex()/sin * PI
Is there some way to have an integer round up to the next integer value when it is greater than half way to the next integer?