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.

Newcomers DBPro Corner / How to turn X,Y,Z into a single digit each?

Author
Message
Mavlock
18
Years of Service
User Offline
Joined: 11th Jan 2006
Location:
Posted: 23rd Jan 2006 15:15
Anyone know how I can turn X,Y,Z into a single digit integer variable?

So instead of objx = 1.5 it would be 1.

Thanks
SirFire
19
Years of Service
User Offline
Joined: 4th Apr 2005
Location: North America
Posted: 24th Jan 2006 05:13 Edited at: 24th Jan 2006 05:15
declare your variables at the beginning of your program to be integers

will print:
1
1
43

Mavlock
18
Years of Service
User Offline
Joined: 11th Jan 2006
Location:
Posted: 24th Jan 2006 05:52
Oh exactly, thanks for the refresh, I pulled a dumb ace there it seems.
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 24th Jan 2006 10:32
ok why does 1.75 become 1?
shouldn't 1.5+ become 2?

life's one big game
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 24th Jan 2006 12:10
No, the integer of 1.75 is 1. The rounded integer of 1.75 is 2.

Easy integers with rounding...

MyInt = ((x * 2) + 1) / 2

SirFire
19
Years of Service
User Offline
Joined: 4th Apr 2005
Location: North America
Posted: 24th Jan 2006 12:11 Edited at: 24th Jan 2006 12:22
Integers have never rounded values (in any of the languages I've ever used). Some languages have a rounding function that provide a closer match to the decimal number than integer. There is no such command I am aware of in DBP. you could make your own rounding function like so:

[EDIT]Batvink, you posted that simple formula while I was making up that function and put me to shame, lol.

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 24th Jan 2006 12:38
SirFire, it's not exactly simple, it just needs a bit of lateral thinking

Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 24th Jan 2006 21:36
int() command anyone?

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 24th Jan 2006 22:28
The int() of 1.75 is 1, as discussed above.

RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 26th Jan 2006 16:01 Edited at: 26th Jan 2006 16:03




<EDIT>

Oh just noticed batvinks, whatever they both work

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 26th Jan 2006 16:14 Edited at: 26th Jan 2006 16:14
Quote: "Value#=INT(Value#)+1"


That would make 1.1 = 2.

I think you could use

Value#=INT(Value#+0.5)

unless anyone can see any holes in it.

RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 26th Jan 2006 22:14 Edited at: 26th Jan 2006 22:15
Well that'd make 1.7 = 1.5, you just need an if statement in there to fix things;


SirFire
19
Years of Service
User Offline
Joined: 4th Apr 2005
Location: North America
Posted: 27th Jan 2006 02:03 Edited at: 27th Jan 2006 02:04
Quote: "Well that'd make 1.7 = 1.5"


Err, no that would make 1.7 = 2.2 (2)



BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 27th Jan 2006 10:37
SirFire is right, it works perfecly well for that scenario.

Login to post a reply

Server time is: 2024-09-24 15:32:39
Your offset time is: 2024-09-24 15:32:39