Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieving a Value from a String 1

Status
Not open for further replies.

bebbo

Programmer
Dec 5, 2000
621
0
0
GB
If I have an example code as below the messgebox displays 1. How can I get it to display 0.5. Proble I have is that I have certain strings which could be 0.5, 1.6, 3.4 etc... I want to convert these strings to a number so that calculations can take place. It appears that I lose the percentage.

If I use Int(Val(aa)) the messagebox displays 0.

aa = "0.5"
b = val(aa)
messagebox(str(b))
 
beddo

How about
messagebox(TRANSFORM(B))

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
beddo

Or even more acurately:

messagebox(TRANSFORM(B,"99.9"))

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Mike

Thanks I've never used Transform before. Just checked it on the Microsoft Help, should be fine.
 
bebbo,
aa = "0.5"
b = val(aa)


You already done it... but when you put that
value to a string use: str(b,5,2) instead of str(b)

hope this works...


Agit Permana (08561052915)
Mitra Solusi Pratama, PT
 
beddo

You will find transform to be quite usefull. It will tranform anything into a character:
MESSAGEBOX(TRANSFORM(.t.))
MESSAGEBOX(TRANSFORM(DATE()))
MESSAGEBOX(TRANSFORM(99))
MESSAGEBOX(TRANSFORM(DATETIME()))

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Thanks

I do appear to have another problem. I've got string values say "0.5". I've also got a Number Filed value in a table (qty).

Should I try and update the field with the string value, as below, the filed is updated with 0. How can I get it to update with 0.5, thanks

REPLACE PACK.Qty WITH Val(TmpQty)

 
Forget my last message, it's sorted. Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top