Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Rounding Numbers

Author
Message
Satchmo
20
Years of Service
User Offline
Joined: 29th May 2005
Location:
Posted: 21st Aug 2008 22:33
Hey all,
What's the fastest way to round a number to 50 in DBC? This is for a locked-to-grid kind of thing.

Thanks in advanced,
-Satchmo

NanoGamez guy
18
Years of Service
User Offline
Joined: 13th Jan 2007
Location: Closer than you think...
Posted: 21st Aug 2008 22:53 Edited at: 21st Aug 2008 22:54
Try:

x/50*50
y/50*50

(don't use floats for this)


On the other hand, you have different fingers.
Robert The Robot
18
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 22nd Aug 2008 14:18
If you're working with floats, though, you might want to try this:



Hope this helps

"I wish I was a spaceman, the fastest guy alive. I'd fly you round the universe, in Fireball XL5..."
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 6th Sep 2008 21:21
Here's a function I made for rounding floats.


It can be adapted to round to any number.
n# is the number to round, r is the number to round to.


example:


It is far better to complete a 10 line program than to start a 10,000 line program.

Login to post a reply

Server time is: 2025-06-07 07:01:14
Your offset time is: 2025-06-07 07:01:14