[Gambas-user] Convert a "currency" string to a number
Charlie Ogier
charlie at cogier.com
Sun Mar 26 17:00:49 CEST 2023
On 25/03/2023 22:38, BB wrote:
> What's the best way to convert a string that looks like "$98,765" or
> "$98,765.43" to an integer / float?
>
> Or putting this another way, I want to test if the value is >
> something (like "sTotal > 50000"), what is the most efficient way to
> do this check.
>
> tia
>
> bruce
>
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
Here's my solution, the routine returns the float value of the string: -
Public Sub Form_Open()
Print CleanValue("$98,765.43")
Print CleanValue("$98,765")
End
Public Sub CleanValue(Value As String) As Float
Dim NewString As String
Dim iLoop As Integer
For iLoop = 0 To Len(Value)
If IsNumber(Value[iLoop]) Then NewString &= Value[iLoop]
Next
Return Val(NewString)
End
Charlie
More information about the User
mailing list