Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Floor Public Function - Results different on two machines

Status
Not open for further replies.

matrix2004

Technical User
Aug 23, 2006
1
US
I inserted the following code into a VB Module to truncate a calculated value to two decimal places. The calculation works fine on my machine but is slightly different on another machine which is located offsite. There are thirteen other offsite centers -- their values agree with mine. The visual basic version number of the one offsite problem location is different than mine but it agrees with the other thirteen offsite centers VB version numbers which I am not encountering any problems with. The object libraries are the same as mine. Regional and Language options computer settings are also the same as mine. Any other ideas?

Public Function Floor(ByVal X As Double, Optional ByVal Factor As Double = 1) As Double
' X is the value you want to round
' is the multiple to which you want to round
Floor = Int(X / Factor) * Factor
End Function

I use the Floor function in various places (queries) which calculated the difference between clock in and clock out. Specifically, I used,

=Floor((DateDiff("n",[TimeOut],[TimeIn])*-1)/60,0.01)

Tanya
 
hmmmmmm ... mmmmmmm other ideas?

I know that the subject has been discussed in these (Tek-Tips) fora in the past most commonly under the guise (name?) of rounding.

If you search for basRoundTo, in these fora, you should be able to find other procedures which are both more general and -perhaps- a bit more robust which you could use to at least see if it also returned different values form hte suspect system.

The only actual thought on your specific issue, would be the actual processor(s). If the odd machine is anolder model CPU, it MIGHT be one with floating point emulation (as opposed to a hardware FPU) or it is even possible that there is a defect / flaw in the FPU itself. A few (thousand?) such cases were reported long away and far ago, but given the vagaries of global warming, I would not be suprised to find it had happened again but without the fanfare of press releases.


Your implementation of "Floor" varies somewhat from the 'deffinition' / example shown in my version of the Excel functions Reference, but looks like it is closefor positive values as long as the error trapping is ignored.




MichaelRed


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top