Print this page

REST API returns different or incorrect 18 digit figure

Knowledge Article Number 000187131
Description - A number field in Salesforce of 18 digits with 0 (zero) decimals contains the value 123456789012345678
- Using the REST API a post is made to /services/data/v28.0/query/?q=SELECT+BIGINT__C+FROM+ACCOUNT
- The RAW response contains: 12345678901234568EXP17
- Some utilities (browser plugins that use Javascript) may truncate this further to 123456789012345680
Resolution - The raw response from the REST API will always be 12345678901234568EXP17 in this case.
- Salesforce will convert numbers greater than 15 digits into scientific (lexical) notation.
- The number is rounded to the nearest suitable digit and the remaining bit information is used to store the lexical notation
- Keep in mind that REST responses in JSON, if further handled in Javascript, will be 'rounded'.  (You can test this in Chrome's console:  <var theNumber = 123456789012345678;  theNumber> returns 123456789012345680.
- The number will be returned in this lexical notation if retrieved with the retrieve() SOAP API call.
- The number will be returned as it is viewed in the database (123456789012345678) if retrieved using the query() SOAP API call (as this returns a String representation of the number)

promote demote