Android Question Parsing a relative string to an integer

Discussion in 'Android Questions' started by Cableguy, Apr 23, 2015.

  1. Cableguy

    Cableguy Expert Licensed User

    Hi guys...

    I have a file that has or will have some relative string values like "1.3%x"... but if I feed this string into a map and try to use it as an integer... it fails... obviously...
    How can I parse this relative string into an integer?

    Thanks
     
  2. DonManfred

    DonManfred Expert Licensed User

    Get the needed subpart of the string (1.3) and cast it to a float or double
    1.3 can not be an int.

    Maybe i did not understand the question right. Dont know what you mean with "relative string"
     
  3. Cableguy

    Cableguy Expert Licensed User

    the string is a screen relative percentage like in the example 1.3%x... if I put this into the map without the quotes it works and gets converted to an integer screen value... but with the quotes I get an error... so i'm guessing I will have that error once I read that value from a file ( not yet implemented)
     
  4. DonManfred

    DonManfred Expert Licensed User

    Sadly b4a does not have a "eval"

    Write the real int behind the relative value into the file and read the int back instead of a string.
    Code:
    log(1.3%x)

    You can write the int value to a file. for the rest you can use YOUR brain :D
     
    Cableguy likes this.
  5. Cableguy

    Cableguy Expert Licensed User

    Lol.... I found a workaround... Not in parsing but in my way of making my calculations
     
    DonManfred likes this.
  6. RandomCoder

    RandomCoder Well-Known Member Licensed User

    Hi @Cableguy is this for what I think it is ;)
    Just store the value you want to use and then multiply it by 1%x or 1%y as required.
     
    Cableguy likes this.
  7. Cableguy

    Cableguy Expert Licensed User

    indeed... I'll send you a new dropbox link ... decided to re-think the whole initialization procedure...
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice