Facility Control

 View Only
  • 1.  Ordinal Suffix on numbers (1st, 2nd, 3rd, 4th....etc)

    Posted 06-24-2017 05:59

    Hi, I'm wondering if there's an easy way to add an ordinal suffix to a number?

    I have an integer parameter that will count up to infinity, but we need to be able to add the ordinal suffix on these numbers.

    I found a piece of Javascript online, but I'm not sure how to translate it for use in Dashboard. Any guidance is appreciated. Thanks

    function getGetOrdinal(n) {
    var s=["th","st","nd","rd"],
    v=n%100;
    return n+(s[(v-20)%10]||s[v]||s[0]);
    }


  • 2.  RE: Ordinal Suffix on numbers (1st, 2nd, 3rd, 4th....etc)

    Posted 06-26-2017 14:51

    My recommendation would be to create a string parameter to hold your completed version. Whenever your numeric value changes, pass its value to your getGetOrdinal function and set your string value to what it returns.

    <abs contexttype="opengear">
       <meta>
          <params>
             <param access="1" constrainttype="INT_NULL" name="Number Entry" oid="p.entry" precision="0" type="INT16" value="0" widget="default"/>
             <param access="1" maxlength="0" name="Number Display" oid="p.display" type="STRING" value="0th" widget="label"/>
          </params>
       </meta>
       <meta>
          <api>function getGetOrdinal(n) 
    {
       var s=["th","st","nd","rd"],
       v=n%100;
       return n+(s[(v-20)%10]||s[v]||s[0]);
    }</api>
       </meta>
       <param expand="true" height="55" left="23" oid="p.entry" runtasksonload="true" showlabel="false" top="20" width="146">
          <task tasktype="ogscript">params.setValue('p.display', 0, getGetOrdinal(params.getValue('p.entry', 0)));</task>
       </param>
       <param expand="true" height="57" left="198" oid="p.display" showlabel="false" style="bdr:etched;bg#dark;txt-align:center;size:Big;font:bold;" top="19" width="150"/>
    </abs>

    #DashBoard


  • 3.  RE: Ordinal Suffix on numbers (1st, 2nd, 3rd, 4th....etc)

    Posted 06-26-2017 15:28
    Perfect, thanks so much James!
    #DashBoard


  • 4.  RE: Ordinal Suffix on numbers (1st, 2nd, 3rd, 4th....etc)

    Posted 06-27-2017 15:21
    Trying to wrap my head around this script. How does it decide on the proper suffix? Where does it decide that 52 needs an "nd" and 53 needs "rd"?
    #DashBoard


  • 5.  RE: Ordinal Suffix on numbers (1st, 2nd, 3rd, 4th....etc)

    Posted 06-27-2017 17:12

    Admittedly, I don't quite understand it either. The only explanation from the site I found it on is:

    function getGetOrdinal(n) {
    var s=["th","st","nd","rd"],
    v=n%100;
    return n+(s[(v-20)%10]||s[v]||s[0]);
    }

    A. find s[v%10] if >= 20 (20th...99th), B. if not found, try s[v] (0th..3rd), C. if still not found, use s[0] (4th..19th)

    There are many ways to do it shown in the link below.[/FONT][/COLOR]


    #DashBoard