Search the web
Sign In
New User? Sign Up
hotbasic
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Show off your group to the world. Share a photo of your group with us.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Floor Ceiling   Message List  
Reply | Forward Message #16635 of 17145 |
Hey Jim,


Whilst we are at it,

in coming to need a ceiling/rounding type function,

and refreshing up on the fpround function,

they all lack the ability to round up/down to a specific range.


Excels Ceiling, floor function caters for this nicely and has spoiled us excel
mavericks.

I have located the algorithm online.

Might it be worthwhile to update the native ceil/floor HB functions to the more
advanced functionality?

Any other users think this might be a nice positive?

The code is below.


'RangedCeilingFloorFunction.bas
'-------------------------------
showconsole

Declare Function Ceiling(ceilingArg As Double, ceilingFactor As Double) As
Double
Function Ceiling(ceilingArg As Double, ceilingFactor As Double) As Double

' ceilingArg is the value you want to round
' ceilingFactor is the multiple to which you want to round

Ceiling = (Int(ceilingArg / ceilingFactor) + (IIF(ceilingArg MOD
ceilingFactor <> 0,1,0))) * ceilingFactor

End Function




Declare Function Floor(floorArg As Double, floorFactor As Double) As Double
Function Floor(floorArg As Double, floorFactor As Double) As Double

' floorArg is the value you want to round
' floorFactor is the multiple to which you want to round

Floor = Int(floorArg / floorFactor) * floorFactor

End Function



print Floor(110.2,10) ' Floor to nearest 10
print Ceiling(13,6) ' Ceiling to Nearest 6

pause



'-------------------------------


credit to: ' http://www.pcreview.co.uk/forums/thread-1692063.php


.enpsuedo





Mon Jul 13, 2009 1:54 pm

enpsuedo
Offline Offline
Send Email Send Email

Forward
Message #16635 of 17145 |
Expand Messages Author Sort by Date

Hey Jim, Whilst we are at it, in coming to need a ceiling/rounding type function, and refreshing up on the fpround function, they all lack the ability to round...
enpsuedo
Offline Send Email
Jul 13, 2009
1:55 pm

... Nice idea, sir! While there is no objection to making such a thing native, may I suggest, since you have prototype code, to create a .lib of those...
doctor electron
globalservices1
Offline Send Email
Jul 13, 2009
4:02 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help