Ask a Question

FieldByName returns integer instead of money

SOLVED
idaj
New Contributor

FieldByName returns integer instead of money

Hello,

I need to get cell's value from a table. I use the following line:
Qry.FieldByName(paramName).Value;

 

The problem is the value is "223,00" or similar, but I always get "223".

Everything works fine if the value is integer.

 

(Qry.FieldByName(paramName).AsFloat does not work)

6 REPLIES 6
Lee_M
Community Hero

Your issue here is that no matter what you type you set the variable to (if using KW) TC will ALWAYS read values as a string

 

you can try using aqConvert to cast your string to a float

 

https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqconvert/strtofloat.html

 

let amount = Qry.FieldByName(paramName).Value;

Log.Message(aqConvert.StrToFloat(amount));

 

or

 

Log.Message(aqConvert.StrToFloat("Qry.FieldByName(paramName).Value"));

 

 

 

 

 

 

idaj
New Contributor

Unfortunately, none of above works. I still get values as "235" instead "235,00" etc.

I don't think that the problem is TC reading values as strings. I think that function "FieldByName" is a problem but I have no idea how to replace it.

Lee_M
Community Hero

Try using the Object spy on the field, you should be able to see what properties are in the field

 

maybe 

- contentText

- wtext

 

may be better suited ?

idaj
New Contributor

I'm trying to gather data from a SQL database, I'm not able to use ObjectSpy.

Lee_M
Community Hero

Sorry, I don't have much experience with TC connecting the DB's so I really can't comment

 

you can try 

https://support.smartbear.com/testcomplete/docs/testing-with/working-with-external-data-sources/data...

or create a support ticket

 

 

but I would try debugging what variable type is coming out of the DB and output it BEFORE you apply any conversion to it

https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqobject/getvartype.html


testVar = Qry.FieldByName(paramName).Value

Log.Message(aqObject.GetVarType(testVar))

 

 

 

it looks like your DB collation maybe not be what you are expecting, some places use (and can set up the DB) ',' as the decimal seperator

 

 

e.g.

 

123.45 (Point 45)

123,456.78 (123 thousand)


Alternative DB collation

123,45 (Point 45)

123.456,78 (123 thousand)



 

in the latter case

223,00 would correctly evaluate to 223 as the .toFloat can't use the ',' collection as a decimal point are far as I know

 

 

- there appear to be 2 decimal places at zero and not 3 which would denote a thousand

you may have to change around , and . if this is the case

sonya_m
SmartBear Alumni (Retired)

Thanks for advice Lee_M!

 

@idaj does this help?


Sonya Mihaljova
Community and Education Specialist

cancel
Showing results for 
Search instead for 
Did you mean: