nan() usage

nan() usage
Hi All, Is any one use the nan() function in your real time project. If so please help me to understand, the real time usage, how and when to use this function
Any help would be greatly appreciated

  Discussion posts and replies are publicly visible

Parents
  • +1
    Certified Lead Developer
    Hi nan() returns null value of type (Number (Decimal)) so instead we do todecimal(null()) manually, alternatively we can go for nan().

    Use Case 1:

    You can have a case, where you have an editable grid which stores the Input Values in CDT array where the fields are not required, and the CDT contains a field Salary of type Number(Decimal). Now your requirement is, you want to get the indexes of all the rows which contains salary as null(). In such case you need to go for wherecontains() where the values will be nan() or todecimal(null()), because you need to have both parameters of same type while using wherecontains()

    Example: Use Case 2:

    wherecontains(
    null(),
    {1.9, 2.9, null(), 4.9}
    )

    OUTPUT: Expression evaluation error at function 'wherecontains' [line 6]: Invalid types, can only act on data of the same type (Text, Number (Decimal))


    wherecontains(
    nan(),
    {1.9, 2.9, null(), 4.9}
    )

    OUTPUT: 3 (List of Number (Integer))


    however you can achieve the same using todecimal(null())

    wherecontains(
    todecimal(null()),
    {1.9, 2.9, null(), 4.9}
    )

    OUTPUT: 3 (List of Number (Integer))

    But as you can compare in above use cases, uses of nan() is much simple instead of converting a null() of type Null into null of Decimal. It's similar to some cases where we can achieve many functionality of Text or Date using Manual manipulation, but it's always a idea to go for predefined functions(if exist) instead of writing of custom logic, which increases the complexity and number of lines of code as well as less readability.

    Hope this will help you...
Reply Children
No Data