Link to home
Start Free TrialLog in
Avatar of Gary Croxford
Gary CroxfordFlag for United Kingdom of Great Britain and Northern Ireland

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(strStringRight))

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
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Gary Croxford

ASKER

Thank you for your help