Question

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
        ]
    }
}
Was it helpful?

Solution

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
                ]
            }
        ]
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top