Hinek
Hinek

Reputation: 9729

Set a custom format for a number field in a SharePoint content type

When I create a content type for SharePoint in XML in Visual Studio. Is it possible to create a field with the Type "Number" and give it a custom format? I don't want the thousands separator, but for some reasons I can't use the type "Integer" ...

EDIT: I tried this without success ...

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <!-- Parent ContentType: Element (0x01) -->
  <ContentType ID="0xMyId"
               Name="MyType"
               Group="MyGroup"
               Description="..."
               Inherits="TRUE"
               Version="0">
    <FieldRefs>
      <FieldRef ID="{5231bb5f-37c8-4ca8-b256-58337cfe82d3}" Name="Right_ID" DisplayName="Right ID" Required="TRUE" />
      <FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" Required="TRUE" />
    </FieldRefs>
  </ContentType>

  <Field ID="{5231bb5f-37c8-4ca8-b256-58337cfe82d3}"
         Type="Number"
         Commas="FALSE"
         Decimals="0"
         Name="Right_ID"
         Group="My Group"
         DisplayName="Right ID"
         StaticName="Right_ID"
         Hidden="FALSE"
         Required="TRUE"
         Sealed="FALSE" />
</Elements>

Maybe I should add, that the target system has german culture, so the thousands separator is . (dot) not , (comma).

Upvotes: 3

Views: 8345

Answers (1)

Rich Bennema
Rich Bennema

Reputation: 10335

If you are creating a custom field, you should be able to set Commas to FALSE in the Field Element. But that attribute is not listed as supported in the FieldRef Element of a Content Type.

EDIT:

I'm beginning to wonder if Commas does not work on Number regardless of locale.

From MSDN (emphasis mine):

Integer Allows for positive or negative integer values. The Commas and NegativeFormat attributes are used to specify integer formatting. Corresponds to the int SQL data type.

and

Number Allows for a floating point number to be entered. This field is sortable and groupable. Numbers entered are parsed according to the current locale settings for decimal points and thousand separators. Negative numbers can be indicated by wrapping them in parentheses or by using a negative symbol. The following attributes can be used in conjunction with the Number attribute to specify number formatting: Decimals, Div, Max, Min, Mult, and Percentage.

With this, to remove the thousands separator I would either:

  1. Try Integer again
  2. Create a Calculated field based on the Number field that removes the comma by converting to text.

Upvotes: 2

Related Questions