Chris
Chris

Reputation: 21

VBA change string with decimal to number with decimal

I have a field in an access database as TEXT. the text has decimals such as 100.00000. need to run calcs on these with the decimals present. Ive been working with the SQL statement and CAST functions and ive had no luck. All I get is whole numbers with no decimals. I've resorted to VBA and I am still getting the same results. every result is whole numbers. I would prefer 5 (FIVE) decimal places.

such as 100.00000 and not "100".

I've tried the split function in VBA and re assembling the 2 strings into a number with the decimal present and still no luck.

The code below pulls in whole numbers only - I need decimal places!! thank you

Function numChange(input1 As String) As Integer

Dim output As Integer

If input1 = "" Then
input1 = 0
End If

output = Format(input1, Number)

numChange = output

End Function

Upvotes: 0

Views: 3742

Answers (1)

Arya
Arya

Reputation: 341

after decimal if no zero will mean a thing, but if you have 100.00001 this will return the same.

Modified:

Function numChange(input1 As String) As Double

Dim output As Double

If input1 = "" Then
input1 = 0
End If

output = Format(input1, "0.00000")

numChange = output

End Function

Upvotes: 0

Related Questions