5 Replies Latest reply on Jun 19, 2017 2:59 PM by rdavin

    Limit number of digits after the ","

    pablo77f

      Hi,

       

      I am working with Analysis template and i have a problem. I need to get a value with two digits after the ",".

      I don't need to round the value. I tried with round(var,2) and format() but it does not work as expected.

       

      Example:

      I have: 1,2345

      I need: 1,23

       

      Can somebody help me??

      Thanks and regards.

       

       

       

        • Re: Limit number of digits after the ","
          Roger Palmen

          What exactly does 'two digits' mean to you?

          The number you say you need is a floating point number having a variable number of digits.How this number is displayed, is controlled by the visualization and/or the PI Points DisplayDigits setting.

           

          If you round to two digits, then the value is rounded to two digits. But beware the syntax: the Round function uses to second argument as: "The size of the unit to round to"

          So if i use Round(1.2345,0.01) the output is 1.23

          2 of 2 people found this helpful
            • Re: Limit number of digits after the ","
              pablo77f

              Hi,

               

              The "Round" function returns a rounded value. I need to truncate the output to two digits.

               

              Example:

              Output

               

               

               

              Round(output, 2)

              round.png

               

               

               

              Roundfrac(output, 2)

              Roundfrac.PNG

               

               

               

               

              Thanks and regards.

                • Re: Limit number of digits after the ","
                  rdavin

                  Just to clarify because Roger Palmen did provide a good answer.  Both Roundfrac and Round will round a number.  If only 1 argument is provided to Round, then its rounds to an integer.  If 2 arguments are provided to Round, it will round to the specified precision.

                   

                  Note that Roundfrac(number, 2) actually calls Round(number, 0.01).  They are equivalent statements.

                   

                  And you are not truncating to 2 digits.  You are indeed rounding with no more than 2 digits.  There is a difference.

                  1 of 1 people found this helpful
              • Re: Limit number of digits after the ","
                rdavin

                Hi Pablo,

                 

                There are 2 functions to round as well well as another function to truncate.  The Trunc function is takes same inputs as Round, so usage is similar to what Roger Palmen posted.  There is also a Roundfrac(number, digits) function.

                 

                Rounding down looks same as Trunc:

                2017-06-19 05_58_52-__DESKTOP-L6P2PBN_Duration Demo - PI System Explorer (Administrator).png

                 

                Rounding up is different from Trunc:

                2017-06-19 05_59_33-__DESKTOP-L6P2PBN_Duration Demo - PI System Explorer (Administrator).png

                • Re: Limit number of digits after the ","
                  pablo77f

                  Hi,

                  Thank you for all answers.

                  I used the "Roundfrac" function and it's works excellent.

                   

                  Thanks and regards.