Need to convert integer MM into decimal inches

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I don't know how.

Trouble is that I need the decimal inches to either the 1/8th or 1/16th, but
integer mm's don't convert to exact 1/8ths. For example: 141mm converts to
5.551181, not 5.5.

Since my CAD software exports in integer mm, and I'd like to use this
calculation on multiple fields, I think it would be most useful as a module.

Anyone know how to do this? Thanks.
 
I'm not sure what you're asking for. If you want to convert mm to inches and
eights then try something like:

Private Function ValInches(valmm As Integer)
Dim valInt, valFractions
valInt = Int(valmm / 25.4)
valFractions = Round(((valmm / 25.4) - Int(valmm / 25.4)) / 0.125, 0)
Select Case valFractions
Case 0
ValInches = valInt
Case 8
ValInches = valInt + 1
Case Else
ValInches = valInt & " " & valFractions & "/8"
End Select
End Function

Cheers.

BW
 
Thanks so much.

What I really need is just the decimal value, rounded to the nearest .125.
Like 5.0, 5.125, 5.25, 5.5... returned as a number so I can further
manipulate it.

I tried stripping out the Select...End Select, but it just returned an empty
field.

thanks again.
 
Actually I need the decimal value, but rounded to the nearest 0.125.

I modified your code to this but I get empty fields in my query.

Option Compare Database

Function valInches(valmm As Integer)
Dim valInt, valFractions, valTotal
valInt = Int(valmm / 25.4)
valFractions = Round(((valmm / 25.4) - Int(valmm / 25.4)) / 0.125, 0)
valTotal = ((valFractions * 0.125) + valInt)
End Function
 
Hi Lumpy

That makes life much simpler. Try:

Private Function valInches(valmm As Integer, valDiv As Integer, valRnd as
Integer)
valInches = Round((Round(((valmm / 25.4) / (1 / valDiv)), 0)) * (1 /
valDiv), valRnd)

You can pass the number of mm's, the divisor and the number of decimal
places for the result. e.g. 33mm to the nearest 16th to 3 decimal places:

your_variable = valInches(33, 16, 3)

Cheers.

BW


End Function
 
IT WORKS!

Thank you very much!


BeWyched said:
Hi Lumpy

That makes life much simpler. Try:

Private Function valInches(valmm As Integer, valDiv As Integer, valRnd as
Integer)
valInches = Round((Round(((valmm / 25.4) / (1 / valDiv)), 0)) * (1 /
valDiv), valRnd)

You can pass the number of mm's, the divisor and the number of decimal
places for the result. e.g. 33mm to the nearest 16th to 3 decimal places:

your_variable = valInches(33, 16, 3)

Cheers.

BW


End Function
 
That's great. By the way, I've assumed that there will always be a whole
number of mm's. If not then just change the declaration to:

Private Function valInches(valmm As Single, valDiv As Integer, valRnd as
Integer)

Cheers.

BW
 
Back
Top