How to store number with more than 15 digits in Sharepoint?

1.1k Views Asked by At

I'm trying to store the value 9234567891234567 in a Number Type SPListItem field. The underlying C# type for a Sharepoint Number Field is Double.

When I assign 9234567891234567 to a double C# var, then it holds 9234567891234568.

SPListItem items = list.GetItemById(siteID);
var value = Convert.ToDouble("9234567891234567");
//pb is that value holds 9234567891234568.0
items[fieldName] = value;
items.Update();
//just to check
double ret = (double) items[fieldName];
Console.WriteLine(ret.ToString("F"));
//outputs 9234567891234570.00
1

There are 1 best solutions below

3
TomTom On

You will hate it, but the answer is "not at all".

https://support.office.com/en-us/article/Site-column-types-and-options-0d8ddb7b-7dc7-414d-a283-ee9dca891df7#__toc277149825

Let me quote:

Both the Number and Currency column types store numerical values. Use a Number column to store numeric data for mathematical calculations that are not financial calculations or do not require a high degree of accuracy. Use a Currency column to store numeric data for financial calculations or in cases where you do not want round numbers in calculations. Unlike a Number column, a Currency column is accurate 15 digits to the left of the decimal point and 4 digits to the right. Both the Number and Currency column types provide predefined formats that determine how data appears.

lists the data types of sharepoint, and both numeric types (number, currency) are limited to 15 digits.

Which means you pretty much must store it as a string, with all the negative consequences that has. Sharepoint exposes a lot less functionality than a raw database, for example in not having large integer only data types.