A common request is to display number fields in SharePoint 2010 lists without commas. For example, if you had a list of books that included PublicationYear column, it would format the values as:
This is confusing to the viewer, as values no longer look like years.
The most frequent suggestion is to create an additional field that calculates a value based on the Number field and ignores all non-numeric parts. This is relatively straightforward, and can be accomplished entirely within the browser:
Or, in a case where you’d like to retain two digits after the decimal:
SharePoint appears to store the data in its numeric format in a another column, hidden to the browser but visible in SharePoint Designer. It’s [column name] followed by a period. For example, I created a field called MyNumericData, so the hidden field is MyNumericData. Again:
Adding this to a view via SharePoint Designer is non-obvious. Here are the steps I used:
- Click on a data item in Design mode until you see a tab labeled xsl:value-of:
- Right-click the item and select Edit Formula
- Remove the current XPath expression
- Add the MyNumericData. row from the fields pane
- Add the format-number function from the Math / Number functions
- Add the appropriate format pattern (e.g. ‘#’)
The appropriate format pattern depends on how you wish to display the data:
- Display integer value:
- Always display two digits after the decimal:
- Display up to 2 digits after the decimal:
If you look at the code view after making these changes, you will see that SharePoint Designer added a hefty chunk of XSL to the XsltListViewWebPart.
Is there any advantage to this method over adding a calculated field? Not as far as I can tell–but it’s interesting to note that there is more than one overly-complicated solution to what seems like a trivial problem.
10 thoughts on “Displaying numeric fields in SharePoint 2010 without commas”
If Gregor Samsa awoke as a programmer, he’d be programming SharePoint. I cannot believe there is no interface for changing number formatting, something that virtually every program has been able to do since 1980. Instead, like so much of SharePoint, there are only workarounds. I feel for Gregor.
This works beautifully for displaying on the page, but what about the filtering drop down? They still have commas.
This works really well. Thankyou for putting this post.
Thanks for sharing this, helped me today.
IT HELPED ME A LOT. THANK YOU VERY MUCH
InfoPath can be used to change the attribute.
Hi, infopath does indeed change it – text box properties / click the Format button, and choose “none (display XML value)”
Thanks for the post – very helpful
So what do you do when you do not have access to Designer because your SharePoint Network guy won’t give you access. Is there a work around with out the use of Designer
This quick custom code ‘=TEXT([MyNumericData], “0”)’ worked charm today for me. Glad to find this piece of code after lot of search online. Thanks man!!