Micro Focus QTP (UFT) Forums
Removing commas from a string and changing it to number - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Removing commas from a string and changing it to number (/Thread-Removing-commas-from-a-string-and-changing-it-to-number)



Removing commas from a string and changing it to number - indranilgoswamimcb - 12-29-2010

Hi,

I have the following query. I am reading the "value" attribute of a webelement and it is containing numbers like 99,99,9910 or 89,012 etc.

I need to eliminate the commas from these numbers and change the data type into numbers like 99999910 and 89012.
I have to write a function for the same in VBscripting in QTP10.

Also, if there is any in built function in QTP then I would like to know the same.

Thanks,
Indranil.


RE: Removing commas from a string and changing it to number - BVVPrasad - 12-29-2010

Hi Indranil,

Try this:

Code:
strData="1,99,98,774"
RetVal=ConvertStringToNumber(strData)
msgbox RetVal

Function ConvertStringToNumber(ByVal Str)
    Str=Cdbl(Replace(Str,",",""))
    ConvertStringToNumber=Str
End Function

Thanks,
Prasad


RE: Removing commas from a string and changing it to number - cdesserich - 12-31-2010

You don't even have to do that. CDbl will work just fine for strings with commas in them. It just ignores them.

Code:
MsgBox CDbl("1,99,98,774")



RE: Removing commas from a string and changing it to number - rajeshwar - 12-31-2010

FormatNumber Function Can be Used.

Code:
i ="1,99,98,774"
msgbox FormatNumber(i,0,0,0,False)