Author Topic: Flooring in FB  (Read 4995 times)

0 Members and 1 Guest are viewing this topic.

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Flooring in FB
« on: May 26, 2006 »
Does anybody know the equivalent command to Floor a number. Floor is a command used in Blitz Basic, and it's meaning is:

Rounds downward, i.e. in the direction of -Infinity

Code: [Select]
Floor(  1.75 ) ......  1.0
Floor( -1.75 ) ...... -2.0 

Cheers and many thanks,
Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: Flooring in FB
« Reply #1 on: May 26, 2006 »
There's not really an equivelant but strangely int(value) seems to do the trick but i dont know why it's not rounding to the nearest instead.

Code: [Select]
dim a as single=-1.1
dim b as single

b=int(a)
print "int(1.1)=";b

a=1.9
b=int(a)
print "int(1.9)=";b

sleep
« Last Edit: May 26, 2006 by Stonemonkey »

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Flooring in FB
« Reply #2 on: May 26, 2006 »
Cheers for that Dude :)

Thanks,
Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline TinDragon

  • Pentium
  • *****
  • Posts: 644
  • Karma: 24
    • View Profile
    • J2K's blog
Re: Flooring in FB
« Reply #3 on: May 26, 2006 »
I suspect that the int() command doesnt actually preform any rounding it just removes the info after the decimal point, something I recall reading about in a C++ book were they suggested adding 0.5 to a number before converting it.

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: Flooring in FB
« Reply #4 on: May 26, 2006 »
If that's the case then surely negative floats would also be rounded toward 0

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Flooring in FB
« Reply #5 on: May 26, 2006 »
Would it be hard to make a function in FB, to do the job of rounding of floor / ceil as in BB.
Would of thought, they'd be an equivalent preset command. It's also strange about int not rounding to the nearest whole number.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: Flooring in FB
« Reply #6 on: May 27, 2006 »
well you can do it by adding/subtracting like tindragon mentioned then converting from float to int and back again but that's probably not the best way but if you want to see other ways then maybe have a look at this, http://www.koders.com/assembler/fidBC013758A0628BCCF9B0980CB8732BFE5B0E559E.aspx.

if you dont use int and just have

dim f as single,i as integer

i=f

then it rounds to the nearest

int(float_value) seems to do the trick for floor and for ceil you'd just do int(float_value+1.0) though.
« Last Edit: May 27, 2006 by Stonemonkey »

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: Flooring in FB
« Reply #7 on: May 27, 2006 »
Check CINT command too, it rounds to nearest integer.

cint(-1.75 ) = -2

cint(1.75 ) = 2

cint(1.3) = 1

cint(1.6 ) = 2
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Flooring in FB
« Reply #8 on: May 27, 2006 »
Cool cheers StoneMonkey And Rbraz. Will do in ze morning.

Many thanks,
Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won: