2

I have created this script to calculate the number of days from today, but it returns like 20 decimals. How to round to a whole number?

I was trying to do this using floor() but I don't understand what the syntax should be like.

Current JSON code I am using:

{
    "elmType": "div",
    "txtContent": {
        "operator": "/",
        "operands": [
            {
                "operator": "-",
                "operands": [
                    "=Number('@now')",
                    "=Number('[$Date]')"
                ]
            },
            86400000
        ]
    }
}

1 Answer 1

1

If you want to use floor() then try below:

{
    "elmType": "div",
    "txtContent": "=floor((Number('@now')-Number('[$Date]'))/86400000)"
}

Note:

floor: returns the largest integer less than or equal to a given number. - Only available in SharePoint Online

  • "txtContent":"=floor(45.5)" results in 45

Source: Use column formatting to customize SharePoint - Operators

Update from Comments:

Using operator and operands you can do it like this:

{
    "elmType": "div",
    "txtContent": {
        "operator": "floor",
        "operands": [
            {
                "operator": "/",
                "operands": [
                    {
                        "operator": "-",
                        "operands": [
                            "=Number('@now')",
                            "=Number('[$Date]')"
                        ]
                    },
                    86400000
                ]
            }
        ]
    }
}
4
  • Thanks, this works! I actually found the source link you added, but didn't yet figure out we can do the calculation without using "operator" and "operand". Thanks for this great example. ps- to round mathmatically correct, I should add half a day to the calucation { "elmType": "div", "txtContent": "=floor(((Number('@now')-Number('[$AdditionDate]')+(0.5 * 86400000))/86400000)" }
    – JJD
    Commented Mar 5, 2020 at 13:10
  • Great. Please Upvote(^) and accept as an Answer if it helped you. Commented Mar 5, 2020 at 13:10
  • I provided the source link just as the reference of floor() function. Commented Mar 5, 2020 at 13:11
  • Check the updated answer. I have provided the solution by using "operator" and "operands". Commented Mar 5, 2020 at 13:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.