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 Professional Discussion / how to round off?

Author
Message
Douglass
21
Years of Service
User Offline
Joined: 28th Aug 2003
Location:
Posted: 11th Aug 2004 04:41 Edited at: 11th Aug 2004 04:42
the problem i have is that when i make a box or cube in darkbasic and i put for example 10 as the size, when i display the size it says its actually 9.9999994 or something like that. is there a way to round off the number so it would be 10.0? bascally i need a command that rounds off numbers to the point you want. do i have to make a function to do this?

and in a totally unrelated question, how do i get the value that ENTRY$()returns to be stored to a variable?

thanks alot,
doug

OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 11th Aug 2004 04:46
Usually you would just add 0.5. However, in DBPro, its a bit more involved - find the decimal point and ignore everything after that (or you can use my VALF command - but that only works with strings).

Quote: "and in a totally unrelated question, how do i get the value that ENTRY$()returns to be stored to a variable?
"

a$=entry$()


Come to the UK Convention on the 23rd & 24th of October
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 11th Aug 2004 04:54

I came up with this after coming across a similar problem of wanting to show the time to 1 dp. You can use this, although it doesn't actually round the numbers up - it just knocks off the unwanted digits. You could adapt it to round up quite easily though if you needed to be that accurate.
DrakeX
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location:
Posted: 11th Aug 2004 05:11
or if you want a plain integer for the size, you could just put the size from OBJECT SIZE X() into an integer instead of a float.

i'm not sure why DBP has problems with float accuracy. they say it's because it's difficult to represent numbers with the floating point format PCs use but i never have these weird inconsistencies with C++.

OK enough of that damn DBP fanboy banner. i'm NOT a DBP fanboy in any way. i haven't used DBP in over a year, and i don't really plan on using it again.
NathanF
21
Years of Service
User Offline
Joined: 24th Mar 2004
Location:
Posted: 11th Aug 2004 12:00
This is what I use:


"I....I like rice?"
Douglass
21
Years of Service
User Offline
Joined: 28th Aug 2003
Location:
Posted: 11th Aug 2004 12:20

Login to post a reply

Server time is: 2025-06-09 04:30:13
Your offset time is: 2025-06-09 04:30:13