• Resolved blue

    (@life2)


    Hi,

    Is it possible to specify rounding to one decimal but not show the decimal if it’s a zero (e.g. show “1.4” with the decimal but “1.0′ without)?

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author CodePeople2

    (@codepeople2)

    Hello @life2

    Yes, of course, that’s possible. You should use the PREC operation but passing true as the third parameter:

    PREC(X, Y, Boolean) It rounds the number X with Y decimals, and if you pass true as the third parameter, if X is an integer, it returns the integer without decimal places:

    For example, PREC(1.04, 1) returns 1.0, or PREC(6, 1) returns 6.0

    However, PREC(1.04, 1, true) returns 1, and PREC(6,1, true) returns 6

    Best regards.

    Thread Starter blue

    (@life2)

    Okay, but I need to round to the nearest 0.5 which is not possible with PREC. Is there a solution for this?

    Plugin Author CodePeople2

    (@codepeople2)

    Hello @life2

    Yes, that’s possible. In this case, you can use the ROUND operation by passing 0.5 as its second parameter:

    ROUND(X,0.5)

    Furthermore, if you want to ensure that returns like 1.0 are transformed into 1 (or the corresponding integer number), you need only to multiply the result by 1:

    ROUND(X,0.5)*1

    E.g.

    ROUND(4.6,0.5)*1 returns 4.5
    ROUND(4.2,0.5)*1 returns 4
    ROUND(4.8,0.5)*1 returns 5

    Best regards.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘About rounding numbers’ is closed to new replies.