Rounding dimension values

Rounding dimension values

Anonymous
Not applicable
495 Views
2 Replies
Message 1 of 3

Rounding dimension values

Anonymous
Not applicable
Way to round decimal dimension values to the nearest 1/16"? For instance,
43.0599 would display as 43.0625 (On a drawing). Tried playing with
tolerances, but thought it would be better addressed as customization.

Thanks in advance...
0 Likes
496 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
A customer gave me a reference to a website a few weeks ago that contained a
sample that converted a number into a fraction. I modified that code so
that outputting a fraction is outputs a decimal value but rounded off to the
nearest specificied fractional value. In the example below, the 16 says
that you want the value to the nearest 1/16. The four indicates that you
want 4 decimal places in the result.

Public Sub TestRound()
MsgBox RoundToFractional(1.454667, 16, 4)
End Sub

' Variation of fractional converter function found at
' http://vbnet.mvps.org/index.html?code/helpers/numbertofraction.htm
Private Function RoundToFractional(ByVal DecimalNumber As Double, ByVal
LargestDenominator, ByVal DecimalPlaces As Integer) As String
Dim GCD As Long
Dim TopNumber As Long
Dim Remainder As Long
Dim WholeNumber As Long
Dim Numerator As Long
Dim Denominator As Long

WholeNumber = Fix(DecimalNumber)
Denominator = LargestDenominator
Numerator = Format(Denominator * Abs(DecimalNumber - WholeNumber), "0")

If Numerator Then
GCD = LargestDenominator
TopNumber = Numerator

Do
Remainder = (GCD Mod TopNumber)
GCD = TopNumber
TopNumber = Remainder
Loop Until Remainder = 0

Numerator = Numerator \ GCD
Denominator = Denominator \ GCD

RoundToFractional = Format(Numerator / Denominator, "0." &
String(DecimalPlaces, "0"))
Else
RoundToFractional = CStr(WholeNumber)
End If
End Function
--
Brian Ekins
Autodesk Inventor API

"Laminator" wrote in message
news:5206052@discussion.autodesk.com...
Way to round decimal dimension values to the nearest 1/16"? For instance,
43.0599 would display as 43.0625 (On a drawing). Tried playing with
tolerances, but thought it would be better addressed as customization.

Thanks in advance...
0 Likes
Message 3 of 3

Anonymous
Not applicable

Where do I put this code to accomplish the result

0 Likes