Simple way to round

BlitzMax Forums/BlitzMax Programming/Simple way to round

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

TomToad

Im not at my home PC so I cant try it but what if you did the following.

f/abs(f) should give either 1 or -1
go one further and f/abs(2*f) should give 0.5 or -0.5

so I think you can do :

i = f + (f / abs(f*2))

so you will either add or subtract 0.5 from f.

(I think)

[edit]
duh !

or you can just do an if statement

Local i:Int
Local f:Float
f= -2.4

if f < 0 then
i=f-0.5
else
i=f+0.5
end if

Print i

[/edit]