Micro Focus QTP (UFT) Forums
Convert a Currency value 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: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Convert a Currency value to number (/Thread-Convert-a-Currency-value-to-number)



Convert a Currency value to number - egun - 08-10-2009

I am trying to clear the comma that I'm picking up in an output value I've recorded (14,800.18). I would like to set/convert it to be 14800.18. How can I go about doing that?

I am trying to compare it to a numeric value and it's failing because of the comma I think.

Code:
DbTable("DbTable_4").Output CheckPoint("DbTable_4")
Browser("V").Page("V").WebElement("14,800.18").Output CheckPoint("14,800.18")

'here I'm getting 14800.18
value5 = Datatable.Value("DbTable_TAmount")
'here I'm getting 14,800.18
value6 = Datatable.Value("_charges_innertext_out")

If Trim(value5) = Trim(value6) Then
foundC = True
Reporter.ReportEvent micPass, "found", "TAmount is correct."
Else
foundC = false
Reporter.ReportEvent micFail, "found", "TAmount is INCORRECT."
End if



RE: Convert a Currency value to number - Saket - 08-11-2009

Hi egun,
Use cdbl instead of Trim while comparing will solve your issue

If cdbl(value5) = cdbl(value6) Then


RE: Convert a Currency value to number - basanth27 - 08-11-2009

Egun -

Are you importing the data from Excel Sheet ?? Because if you are entering the data into the datatable, Datatasheet blindly eliminates all the special charachters . Never mind, just curious to know.

Try this, I have modified your code.

Code:
DbTable("DbTable_4").Output CheckPoint("DbTable_4")
Browser("V").Page("V").WebElement("14,800.18").Output CheckPoint("14,800.18")

'here I'm getting 14800.18
value5 = Datatable.Value("DbTable_TAmount")
'here I'm getting 14,800.18
value6 = Datatable.Value("_charges_innertext_out")
value6 = Replace(value6, ",", "")
If Trim(value5) = Trim(value6) Then
foundC = True
Reporter.ReportEvent micPass, "found", "TAmount is correct."
Else
foundC = false
Reporter.ReportEvent micFail, "found", "TAmount is INCORRECT."
End if
Let me know if it worked or it helped you or this exactly what you were looking for.


RE: Convert a Currency value to number - Saket - 08-11-2009

great, Replace is also a good idea, But I feel, if we need to compare numeric values then we should use cdbl.
what say, Basanth27?


RE: Convert a Currency value to number - basanth27 - 08-11-2009

Saket -
You know what, I looked at egun's code and saw that he was reffering closely to the numeric conversions. But if it deals or anything dealing with Currency formats etc..cdbl is an excellent option.

Thanks saket for bringing it up and sharing it.

Egun - You have 2 options now :-) pick your choice.

Unsure why i have no option to Edit..it throws a error. Just a quick snippet about CDBL.

This one from QTP Help...

Use the CDbl function to provide internationally aware conversions from any other data type to a Double subtype. For example, different decimal separators and thousands separators are properly recognized depending on the locale setting of your system.

This example uses the CDbl function to convert an expression to a Double.

Dim MyCurr, MyDouble
MyCurr = CCur(234.456784) ' MyCurr is a Currency (234.4567).
MyDouble = CDbl(MyCurr * 8.2 * 0.01) ' Convert result to a Double (19.2254576).

- basanth


RE: Convert a Currency value to number - egun - 08-11-2009

Thank you both for your input - the CDbl function worked for me... I appreciate the help as always.

egun