raviprakash
New Member
Hi,
I have a code which converts inch dimensions to mm. The problem is it won't print the zero after decimals like if the output is 1.20, it will print 1.2.
Please check the below code and let me know how to overcome this problem.
If anyone knows, please help me.
Thanks in advance.
Regards,
Ravi
I have a code which converts inch dimensions to mm. The problem is it won't print the zero after decimals like if the output is 1.20, it will print 1.2.
Please check the below code and let me know how to overcome this problem.
Code:
Function inchTomm(max As Double, min As Double, convtype As String)
Dim decimals As Integer
Dim tolerance As Double
Dim significant_digits As Integer
tolerance = max - min
significant_digits = Len(CStr(max)) - Len(CStr(Application.WorksheetFunction.RoundUp(max, 0)))
tolerance = Application.WorksheetFunction.RoundUp(tolerance, significant_digits)
If tolerance >= 0 And tolerance < 0.0004 Then
decimals = 4
Else
If tolerance >= 0.0004 And tolerance < 0.004 Then
decimals = 3
Else
If tolerance >= 0.004 And tolerance < 0.04 Then
decimals = 2
Else
If tolerance >= 0.04 And tolerance < 0.4 Then
decimals = 1
Else
If tolerance >= 0.4 Then
decimals = 0
End If
End If
End If
End If
End If
If convtype = "max" Or convtype = "Max" Or convtype = "MAX" Then
inchTomm = Application.WorksheetFunction.RoundDown(max * 25.4, decimals)
Else
If convtype = "min" Or convtype = "Min" Or convtype = "MIN" Then
inchTomm = Application.WorksheetFunction.RoundUp(min * 25.4, decimals)
'& " d: " & decimals & " t: " & tolerance
End If
End If
End Function
&
If anyone knows, please help me.
Thanks in advance.
Regards,
Ravi