{"id":570,"date":"2011-11-09T18:41:19","date_gmt":"2011-11-09T23:41:19","guid":{"rendered":"http:\/\/osric.com\/chris\/accidental-developer\/?p=570"},"modified":"2011-11-09T18:44:38","modified_gmt":"2011-11-09T23:44:38","slug":"displaying-numeric-fields-in-sharepoint-2010-without-commas","status":"publish","type":"post","link":"https:\/\/osric.com\/chris\/accidental-developer\/2011\/11\/displaying-numeric-fields-in-sharepoint-2010-without-commas\/","title":{"rendered":"Displaying numeric fields in SharePoint 2010 without commas"},"content":{"rendered":"<p>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  <em>PublicationYear<\/em> column, it would format the values as:<\/p>\n<ul>\n<li>2,001<\/li>\n<li>1,998<\/li>\n<li>2,011<\/li>\n<\/ul>\n<p>This is confusing to the viewer, as values no longer look like years.<\/p>\n<p>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:<\/p>\n<p><code>=TEXT([MyNumericData], \"0\")<\/code><\/p>\n<p>Or, in a case where you&#8217;d like to retain two digits after the decimal:<br \/>\n<code>=TEXT([MyNumericData], \"0.00\")<\/code><\/p>\n<p>SharePoint appears to store the data in its numeric format in a another column, hidden to the browser but visible in SharePoint Designer. It&#8217;s [column name] followed by a period. For example, I created a field called MyNumericData, so the hidden field is MyNumericData<strong>.<\/strong> Again:<\/p>\n<ul>\n<li>MyNumericData<\/li>\n<li>MyNumericData<strong>.<\/strong><\/li>\n<\/ul>\n<p>Adding this to a view via SharePoint Designer is non-obvious. Here are the steps I used:<\/p>\n<ol>\n<li>Click on a data item in Design mode until you see a tab labeled <em>xsl:value-of<\/em>:<br \/>\n<figure id=\"attachment_573\" aria-describedby=\"caption-attachment-573\" style=\"width: 230px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/osric.com\/chris\/accidental-developer\/wp-content\/uploads\/2011\/11\/MyNumericData-xsl-value-of.png\" alt=\"\" title=\"MyNumericData-xsl-value-of\" width=\"230\" height=\"110\" class=\"size-full wp-image-573\" \/><figcaption id=\"caption-attachment-573\" class=\"wp-caption-text\">SharePoint Designer 2010 Design Mode<\/figcaption><\/figure><\/li>\n<li>Right-click the item and select <em>Edit Formula<\/em><\/li>\n<li>Remove the current XPath expression<\/li>\n<li>Add the MyNumericData<strong>.<\/strong> row from the fields pane<\/li>\n<li>Add the <em>format-number<\/em> function from the <em>Math \/ Number<\/em> functions<\/li>\n<li>Add the appropriate format pattern (e.g. &#8216;#&#8217;)<\/li>\n<\/ol>\n<p>The appropriate format pattern depends on how you wish to display the data:<\/p>\n<ul>\n<li>Display integer value:<br \/>\n<code>format-number($thisNode\/@MyNumericData.,'#')<\/code><\/li>\n<li>Always display two digits after the decimal:<br \/>\n<code>format-number($thisNode\/@MyNumericData.,'0.00')<\/code><\/li>\n<li>Display up to 2 digits after the decimal:<br \/>\n<code>format-number($thisNode\/@MyNumericData.,'#.##')<\/code><\/li>\n<\/ul>\n<p>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.<\/p>\n<p>Is there any advantage to this method over adding a calculated field? Not as far as I can tell&#8211;but it&#8217;s interesting to note that there is more than one overly-complicated solution to what seems like a trivial problem.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The number field in a SharePoint list gives you a few basic formatting options (# of decimal places, include % sign), but automatically adds a comma as a thousands-separator. For some numeric data, e.g. Year of Publication, this would be inappropriate. This article describes 2 ways to apply formatting to remove the thousands separators.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[180],"tags":[230,160,211,229],"class_list":["post-570","post","type-post","status-publish","format-standard","hentry","category-sharepoint-2","tag-formatting","tag-sharepoint","tag-sharepoint-2010","tag-sharepoint-designer"],"_links":{"self":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/570","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/comments?post=570"}],"version-history":[{"count":4,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/570\/revisions"}],"predecessor-version":[{"id":576,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/570\/revisions\/576"}],"wp:attachment":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/media?parent=570"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/categories?post=570"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/tags?post=570"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}