# Thread: How to convert a STRING “9999.99” into INTEGER 9999.99 ?

1. ## How to convert a STRING “9999.99” into INTEGER 9999.99 ?

How to convert a STRING into INTEGER?

eg. STRING “9999.99” into INTEGER 9999.99

[This message has been edited by Prasad (edited 01-18-2001).]

2. ## Re: How to convert a STRING “9999.99” into INTEGER 9999.99 ?

Well, the standard way of converting a string representation of a number into a numeric type, is by use of the Str() function.
e.g. integer i = Str("4568")
You might want to take care though - 9999.99 isn't an integer. You'll need to convert it to a real or number type.

3. ## Re: How to convert a STRING “9999.99” into INTEGER 9999.99 ?

Have you tried using the Val command?

STRING str = 10
INTEGER i

i = Val(str)
print ("i = {i}")
*prints out* i = 10

I'm pretty sure it allows you to specify a real number instead of an integer as well... just check the help menu for "Val".

I think the Str command converts numbers to strings, probably not what you're looking for.

4. ## Re: How to convert a STRING “9999.99” into INTEGER 9999.99 ?

Not sure if it will matter for you, but I though I would mention commas. If your string has commas, you need to strip them out. Here is an example. Note the difference in the output.

[ ] real r
[ ] string s = "999,999.99"
[ ] r=val(s)
[ ] print(r)
[ ] s = strtran(s,",","")
[ ] r=(val(s))
[ ] print(r)

Output:
[ ] 999.000000
[ ] 999999.990000

#### 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.