Convert String to Number for Filtering

Comments

8 comments

  • Stefan Ukena

    Hi Brett,

    you need to use a JavaScript Number-object. Try this:

    Number(@your_text_field)
    

    Note that you probably have to create a new calculation field for this to work, because Podio is kind of picky when it sees the output change from text to numbers.

    Best,
    Stefan

    http://www.diekollaborateure.com/go/podio/help

    0
    Comment actions Permalink
  • Brett Bernstein

    Thanks for the quick reply! I tried and I get the following error:

    "The result is not a valid number"

    Here is my code:

    ID = @All of File No.[0].split(".",1) + ""

    write = Number (ID)

    The field is a number field. When I create a new field and put in the same code, it seems to make it a text field, which doesn't come up in the filtering options. I tested the value of ID and it shows 99,794 (which is the 99794 prefix in a file no 99794.001).

    Any idea why it may not be a valid number?

    0
    Comment actions Permalink
  • Stefan Ukena

    Hi Brett,

    sorry, I forgot this might happen. Podio sometimes uses random "test-data" in calculations which usually is helpful, but in some cases it's not. :/

    When you user Number(x) with an x that really is NOT a number, this results in a special Javascript-Number instance "NaN" (short for NotaNumber) and Podio will refuse to save the calculation.

    To avoid this, return -1 or any number if isNaN(Number(x)) is true, else return Number(x):

    var your_text_field = @Titel;
    
    no_dots = your_text_field.replace(".", "");
    var as_number = Number(no_dots);
    
    if (isNaN(as_number)) {
      -1;
    } else {
      as_number;
    }
    

    Note: once you successfully saved the calculation and it works, you can change this line to return null instead, if you want.

    Hope this helps! Best,
    Stefan

    0
    Comment actions Permalink
  • Brett Bernstein

    Worked!!! Thank you so much!!!

    0
    Comment actions Permalink
  • Rainer Grabowski (FVM)

    Just for information: Christian Holm, the former Podio-CDO, gave me this advice, to force the calculation field to accept a NaN result as number so you can save it:

    parseInt(no_dots, 10) || 0 
    

    " || 0" does the same as:
    if (isNaN(as_number)) {
    -1;
    but it's faster to write :) .

    Rainer

    1
    Comment actions Permalink
  • Stefan Ukena

    @Rainer: good point about using parseInt() here, thanks!

    (I simply can never remember JavaScript's crazy type-conversion and true/false evaluation rules, so I will never be able to remember to use || 0 :) )

    0
    Comment actions Permalink
  • Brett Bernstein

    Thanks for the alternative solution, Rainer!

    0
    Comment actions Permalink
  • Mike Davis

    Just before I found this post, I screamed into the air, "Where is Rainer? He would know."

    Rainer, You always have the answers. Every time. The Podio Demi-Diety. There is also Andreas (either one), but you guys are all on the same level in my book. If I was on myspace still, I would put you in my top 8....maybe 4...if I could convince you to be my friend on myspace.

    :Werenotworthywayne'sworldgif:

    I could probably tone it down with a simple thank you. 

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk