Gary Croxford
asked on
VBA Format() and decimal places - not performing as I'd expected
Thank you for looking at my question,
I am extracting number values from text strings such as in the example below:
strstring = "Storage Zone : Maximum Order Quantity : 99999999.0000 [pcs],"
strString = Right(String, len(String)-74)
lngMaxOrdQty = CLng(getTextWithUnits(strS tringRight ))
Function getTextWithUnits(s As String) As String
Dim Arr1() As String
Dim Arr2() As String
Arr1 = Split(s, ":", , vbTextCompare)
If InStr(Arr1(1), " ") > 0 Then
Do Until InStr(Arr1(1), " ") = 0
Arr1(1) = Replace(Arr1(1), " ", " ")
Loop
End If
Arr2 = Split(Arr1(1), " ", , vbTextCompare)
getTextWithUnits = LTrim(Arr2(1))
End Function
The function extracts the value "99999999.0000" as a string but when I convert it to a long value it loses the decimal point and the four decimal places - 99999999
I have tried Format(lngMaxOrdQty, "0.0000") but this still returns 99999999
Please can anybody tell me what I've missed
I am extracting number values from text strings such as in the example below:
strstring = "Storage Zone : Maximum Order Quantity : 99999999.0000 [pcs],"
strString = Right(String, len(String)-74)
lngMaxOrdQty = CLng(getTextWithUnits(strS
Function getTextWithUnits(s As String) As String
Dim Arr1() As String
Dim Arr2() As String
Arr1 = Split(s, ":", , vbTextCompare)
If InStr(Arr1(1), " ") > 0 Then
Do Until InStr(Arr1(1), " ") = 0
Arr1(1) = Replace(Arr1(1), " ", " ")
Loop
End If
Arr2 = Split(Arr1(1), " ", , vbTextCompare)
getTextWithUnits = LTrim(Arr2(1))
End Function
The function extracts the value "99999999.0000" as a string but when I convert it to a long value it loses the decimal point and the four decimal places - 99999999
I have tried Format(lngMaxOrdQty, "0.0000") but this still returns 99999999
Please can anybody tell me what I've missed
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER