access 97 floor function

  • Thread starter Thread starter Marv
  • Start date Start date
M

Marv

Can I duplicate the floor function in Excel in Access 97?
I need to round down to the nearest tenth.
example 12.1234 to 12.1
12.1799 to 12.1

Thanks,
Marv
 
Marv said:
Can I duplicate the floor function in Excel in Access 97?
I need to round down to the nearest tenth.
example 12.1234 to 12.1
12.1799 to 12.1


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

This is a function I obtained from MS's NeatCode97.mdb example file:

Function Floor(N, ByVal Precision)
'
' Similar to Excel's Floor function
' Rounds down (toward zero) to the next higher level of precision.
' Precision cannot be 0.
'
Precision = Abs(Precision)
Floor = Int(N / Precision) * Precision
End Function

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQIWqN4echKqOuFEgEQK4RgCdFM+GyrKQCNAdVpjoa4U8KFLi3A0AoKl0
Vi461d0dg0fcAFg+mt4nBZ+G
=UXYH
-----END PGP SIGNATURE-----
 
Just for the record (and meaning no offense),


Works:
--------------
? (int(12.1234 / .1) * .1)
12.1
? (int(12.1799 / .1) * .1)
12.1

Unexpected Results:
---------------------
? (int(12.0 / .1) * .1)
11.9
? (int(12.0000000000000001 /.1) * .1)
11.9


One option (for Access versions that support CDec()):
------------------------------------------------------
? (int(CDec(12.0) /CDec(.1)) * CDec(.1))
12
? (int(CDec(12.0000000000000001) /CDec(.1)) * CDec(.1))
12

You may only need to use CDec in division

? (int(CDec(12.1234) /CDec(.1)) * .1)
12.1
? (int(CDec(12.199999) /CDec(.1)) * .1)
12.1
? (int(CDec(12.09999) /CDec(.1)) * .1)
12
? (int(CDec(12.0000000000000001) /CDec(.1)) * .1)
12

but you might use var in FLOOR function
to change Precision to Dec, then could use
var in both places.

I believe it is only the division and subtraction
of non-integers where this is a problem. To make
sure I'm not wrong, it would not hurt to read:

When Access Math Doesn't Add Up
by Luke Chung President of FMS
http://www.fmsinc.com/tpapers/math/index.html

Again, meaning no offense.

Gary Walter
 
I believe it is only the division and subtraction
of non-integers where this is a problem. To make
sure I'm not wrong, it would not hurt to read:

When Access Math Doesn't Add Up
by Luke Chung President of FMS
http://www.fmsinc.com/tpapers/math/index.html

That should read:

I believe it is only
- division of real numbers
- subtraction of real numbers
- equality of real numbers
- passing of real numbers to an Access function
(like Int() )
- rounding of real numbers

that can cause problems.

And, for me, CDec() seems to be the magic bullet.

But, please read Luke's article in case I am wrong.

Thanks,

Gary Walter
 
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

No offense taken. Whatever works correctly. Thanks for pointing out
that article.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)


-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQIbW0IechKqOuFEgEQIaWQCgrGRao2Br+lQa/gE8H6dd1+QUhXkAoKhL
v69FBYCb2g9fpy7X27stNXIX
=Ea5S
-----END PGP SIGNATURE-----
Gary said:
Just for the record (and meaning no offense),


Works:
--------------
? (int(12.1234 / .1) * .1)
12.1
? (int(12.1799 / .1) * .1)
12.1

Unexpected Results:
---------------------
? (int(12.0 / .1) * .1)
11.9
? (int(12.0000000000000001 /.1) * .1)
11.9


One option (for Access versions that support CDec()):
------------------------------------------------------
? (int(CDec(12.0) /CDec(.1)) * CDec(.1))
12
? (int(CDec(12.0000000000000001) /CDec(.1)) * CDec(.1))
12

You may only need to use CDec in division

? (int(CDec(12.1234) /CDec(.1)) * .1)
12.1
? (int(CDec(12.199999) /CDec(.1)) * .1)
12.1
? (int(CDec(12.09999) /CDec(.1)) * .1)
12
? (int(CDec(12.0000000000000001) /CDec(.1)) * .1)
12

but you might use var in FLOOR function
to change Precision to Dec, then could use
var in both places.

I believe it is only the division and subtraction
of non-integers where this is a problem. To make
sure I'm not wrong, it would not hurt to read:

When Access Math Doesn't Add Up
by Luke Chung President of FMS
http://www.fmsinc.com/tpapers/math/index.html

Again, meaning no offense.

Gary Walter
< snip>
 
Back
Top