PDA

View Full Version : Truncate and Rounding



MrRhodes2004
12-27-2007, 10:08 AM
The following creates rounding error = don't want rounding - want truncation.

Function Azmth2Brng(lBearing As Single) As String
lBearing = lBearing - (Int(lBearing / 360) * 360)
Debug.Print lBearing
End Function
Sub testy()
Azmth2Brng (44465.32)
End Sub

I get 185.3203 WHY? Should it not be 185.32?

Where does .0003 come from and how do I eliminate it?

Bob Phillips
12-27-2007, 10:12 AM
Function Azmth2Brng(lBearing As Single) As Double
lBearing = Round(lBearing - ((lBearing \ 360) * 360), 2)
Debug.Print lBearing
End Function

MrRhodes2004
12-27-2007, 10:19 AM
Single vs Double? Since the object is only a number to the hundreth decimal place, why should I have to use a double to get an accurate answer?

The string portion is for the final output of the result. The object is to bring in a decimal azmuth and convert it to a bearing: 10.345 degrees = N 10d20'42'' E

Bob Phillips
12-27-2007, 10:44 AM
It was the rounding that gave the accuracy, not the double. I just never work in Single or Integer.

Even if it is to be converted to a bearing, I would get the function to return a number and append the text outwith the function.