Ad Widget

Collapse

Round number to N decimal places..

Collapse
This topic has been answered.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alfista
    Senior Member
    • Mar 2017
    • 136

    #1

    Round number to N decimal places..

    Hi,

    please can you help me how can I round the number to N decimal places that I get from the item CPU utilization, that I dont have there too many decimal places (need 2)?

    I have tried using preprocesing in and the java with functions: string.format(), decimalformat() but nothing was working.
    The system told me that it doesnt know this functions.

    Please can you help me?

    Thanks.
  • Answer selected by Alfista at 29-09-2022, 11:48.
    Hamardaban
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • May 2019
    • 2713

    Code:
    return parseFloat(value).toFixed(2);
    Code:
    return Math.round(parseFloat(value) * 100) / 100;
    Last edited by Hamardaban; 28-09-2022, 16:44.

    Comment

    • Hamardaban
      Senior Member
      Zabbix Certified SpecialistZabbix Certified Professional
      • May 2019
      • 2713

      #2
      Code:
      return parseFloat(value).toFixed(2);
      Code:
      return Math.round(parseFloat(value) * 100) / 100;
      Last edited by Hamardaban; 28-09-2022, 16:44.

      Comment

      • Alfista
        Senior Member
        • Mar 2017
        • 136

        #3
        Thanks, this is working greate.

        Comment

        • ESITGuy
          Junior Member
          • Mar 2023
          • 17

          #4
          Any advice on how to apply this globally? Not sure I ever want to see 4 decimal places.

          Would be a nice option in User Profile next to Rows per page.​

          Comment


          • Alfista
            Alfista commented
            Editing a comment
            This is a great idea, to save space in DB and have more speed in action, while no one need so many decimal places :-)
        • Hamardaban
          Senior Member
          Zabbix Certified SpecialistZabbix Certified Professional
          • May 2019
          • 2713

          #5
          I agree - but contact the developers with this

          Comment

          Working...