2 Replies Latest reply on Nov 26, 2014 11:04 PM by JavierDura

    Round up in a list

    JavierDura

      Do you know any custom function that rounds up (like the Ceiling function) a number according to a list of numbers?

       

       

      Something like this:

       

      RoundCF ( theList ; theValue )

       

      RoundCF ( 2 ¶ 3.5 ¶ 7.2 ¶ 15 ; 4 ) returns 7.2

      RoundCF ( 2 ¶ 3.5 ¶ 7.2 ¶ 15 ; 7.3 ) returns 15

       

      Thanks!

        • 1. Re: Round up in a list
          erolst

          Javier Durá wrote:

          rounds up (like the Ceiling function) a number …  returns  7.2

           

          I'm not sure how "round up" should produce a number with a decimal part …what you mean is: return the next larger element from the list?!

           

          Assuming theList is pre-sorted, try

           

          // FindLargerInList ( theList ; theValue ) =

          Let ( [

            first = GetAsNumber ( GetValue ( theList ; 1 ) ) ;

            last = GetAsNumber ( RightValues ( theList ; 1 ) ) ;

            v = theValue

            ] ;

            Case (

              v >= last ; v ;

              first > v ; first ;

              FindLargerInList ( RightValues ( theList ; ValueCount ( theList ) - 1 ) ; v )

            )

          )

          • 2. Re: Round up in a list
            JavierDura

             

            I'm not sure how "round up" should produce a number with a decimal part …what you mean is: return the next larger element from the list?!

             

             

            Yes, you are right. That´s what I need.

            Thank you for your help!