Thread: How do you convert \$2.00 to numeric value.

1. How do you convert \$2.00 to numeric value.

I use obj_get_text on a HTA or HTML page. The object is # \$2.00. When I try to do any math function the output is 0. Aperantly is treated as a text instead of numeric field.

------------------

2. Re: How do you convert \$2.00 to numeric value.

You could use match() and substr(), something like:

test = "\$2.00";
printf("Start: %s", test);
dollar_pos = match(test, "\$");
test = substr(test, dollar_pos + 1);
printf("End: %f", test);

------------------
Charles Reace

charles{DOT}reace{AT}verizon{DOT}net

3. Re: How do you convert \$2.00 to numeric value.

Here is a library function I wrote that does exactly what you want.

################################################## #################
# rawnum
# Purpose: This function will purge the following (" ",",","\$")
# characters from the OrigText string. It is ment to remove
# formating from numbers that may be used in comparisons.
#
# Input Parameters:
# OrigText: The string to remove the characters from.
# Output Parameters:
# ModText: This is the string after the character has been purged
# Return Values
# E_OK: If function completes correctly.
################################################## #################
public function rawnum(inout OrigText,out ModText)
{
auto BefText;
auto AftText;
auto Loc;
auto NumArray[];
auto Elements;

ModText = OrigText;
BefText = "";
AftText = "";
Elements = 0;

#Strip out the " " characters
while (index(ModText," ")>0){
Loc = index(ModText," ");
BefText = substr(ModText,1,Loc-1);
AftText = substr(ModText,Loc+1);
ModText = BefText & AftText;
}

#Strip out the "," characters
while (index(ModText,",")>0){
Loc = index(ModText,",");
BefText = substr(ModText,1,Loc-1);
AftText = substr(ModText,Loc+1);
ModText = BefText & AftText;
}
#Strip out the "\$" characters
while (index(ModText,"\$")>0){
Loc = index(ModText,"\$");
BefText = substr(ModText,1,Loc-1);
AftText = substr(ModText,Loc+1);
ModText = BefText & AftText;
}

#Strip out trailing decimal point if nothing to the right.
Elements = split(ModText,NumArray,".");
if (Elements == 2){
if (NumArray[2] == ""){
ModText = NumArray[1];
}else{
ModText = NumArray[1] & "." & NumArray[2];
}
}
return (E_OK);
}

------------------

4. Re: How do you convert \$2.00 to numeric value.

spend \$1.01

that will get rid of the \$ sign

------------------
GUI automation is GUI automation. It is not testing.

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 06:21 AM.