SPONSORS:






User Tag List

Results 1 to 7 of 7
  1. #1
    Junior Member
    Join Date
    Jun 2001
    Posts
    13
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Casting a string to an integer...

    I have a string in the format "1.50" and I would like to convert it to a number. I have tried casting such as [Integer]String but I get an ASCII value instead of the number 1.50 which is what I want since this value will be added up recursively to get a total.

    Any ideas?
    Thanks

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

  2. #2
    Member
    Join Date
    Jun 2001
    Location
    Berkeley, CA, USA
    Posts
    67
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Casting a string to an integer...

    Try using the Val function.

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

  3. #3
    Senior Member
    Join Date
    Jul 1999
    Location
    Bellingham, WA USA
    Posts
    1,323
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Casting a string to an integer...

    Exactly... You can convert these back and forth as needed using the Val() and Str() functions.

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

  4. #4
    Senior Member
    Join Date
    Jan 2001
    Posts
    750
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Casting a string to an integer...


    print(str(1.5,Len(str(1.5)),3))

    str() needs to put the decimal you want it's not always dynamic while converting from (float) to string.

    val works fine with just too many zeros appended to it.

    I would prefer just to use your own function

    string myStr(int i)
    return "{i}"

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

  5. #5
    Junior Member
    Join Date
    Jun 2001
    Posts
    13
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Casting a string to an integer...

    Thanks guys... thats exactly what I needed!

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

  6. #6
    Member
    Join Date
    Dec 2000
    Location
    San Francisco, CA
    Posts
    51
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Casting a string to an integer...

    GodKnows,

    print(str(1.5,Len(str(1.5)),3))

    Whats 'Len(str(1.5))' for?

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

  7. #7
    Mel
    Mel is offline
    Junior Member
    Join Date
    Mar 2001
    Location
    San Jose, CA, USA
    Posts
    28
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Casting a string to an integer...

    Does anybody have a library of such useful functions? Ex: Casting string to integer and vice versa, changing a string to hexadecimal value, etc. I would be nice to share it with the SilkTest community. These would be practical when doing some verifications.

    Thanks.
    Mel

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

 

 

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.
User Alert System provided by Advanced User Tagging v3.0.9 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Questions / Answers Form provided by vBAnswers (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominatevBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - 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 02:13 PM.

Copyright BetaSoft Inc.