Removing commas from number fields in SharePoint online view items

In this article I will show (and reference) a neat piece of formatting code I found to change a year of 2020 from 2,020 to 2020 in a list view

The Problem

Simply put, if you have a number in a list in SharePoint it will add number formatting by default. A view with a Year number value of 2020 will display as 2,020

The solution

Using Colulumn formatting you can superceed the default formatting by replacing the value displayed in the field with a text value of the same thing

I found the solution on stackexchange – https://sharepoint.stackexchange.com/a/269817/48559

Select the option to format the column

Add the following into the formatting box (advanced mode)

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "attributes": {
    "class": "=if(@currentField > 0,'', '')"
  },
  "children": [
    {
      "elmType": "span",
      "style": {
        "display": "inline-block"
      }
    },
    {
      "elmType": "span",
      "txtContent": "@currentField"
    }
  ]
}

And there you have it

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s