Android Question Replacing zero values with "-" in tables (inline code)

Discussion in 'Android Questions' started by Arf, Mar 16, 2015.

  1. Arf

    Arf Active Member Licensed User

    In the case of the app I'm making, I am showing numeric results (usually in the format 1.23), but I wish to parse out zero values and instead of displaying as "0.00", I want to display them as "-".

    In C I can do an inline test and substitution like this:
    Results.Measurement == 0.0 ? "-" : Results.Measurement
    to use a dash if the result is zero.

    Is there any b4a equivalent, or should I just create a function to do it?
     
  2. Arf

    Arf Active Member Licensed User

    I have tried to create a function, the problem I'm having is with casting.
    When setting up the table with list.Add function I can add strings or values and the right thing gets displayed.
    The function I created returns strings, and I get an error - java.lang.NumberFormatException: Invalid double "-" when a result is zero.
    So, I guess at compile time the ability to deal with the result as either String or Double gets lost if I use my function.
     
  3. Arf

    Arf Active Member Licensed User

    Ah, the problem was that I was still dividing the number by 100 in the .Add function, error gone and works OK now.
    If there is an inline substitution test similar to the C one I would still like to know though. thanks.
     
  4. DonManfred

    DonManfred Expert Licensed User

    AFAIK b4a does not support ternary operators
     
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