Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Although not conclusive, based on the following tests it looks like SharePoint handles numbers in a way suitable for monetary calculations (at least with WSS 3.0/SQL Server 2005) even though they are stored approximately. However, <strong>values with over 15 significant figures can exhibit rounding errors</strong>:</p> <p><strong>Test for money storage and retrieval</strong></p> <p>Three number columns (<code>First</code>, <code>Second</code> and <code>Third</code>) containing 3.7, 3.65 and 0.05 respectively (.Net example from <a href="https://stackoverflow.com/questions/316727/is-a-double-really-unsuitable-for-money/316731#316731">here</a>) and a calculated column (returning a single line of text) with the following formula: <code>=IF(First=Second+Third,"Success","Failure")</code>. On viewing the list the calculated column displays <strong>Success</strong>.</p> <p><strong>Test for money calculations</strong></p> <p>A Yes/No calculated column with the formula <code>=0.1+0.1+0.1=0.3</code> (.Net example from <a href="https://stackoverflow.com/questions/316727/is-a-double-really-unsuitable-for-money/316737#316737">here</a>). On viewing the list the calculated column displays <strong>Yes</strong>.</p> <p><strong>Test for money storage and calculation I</strong></p> <p>In a list called <code>TestList</code>, a custom number column (<code>CustomNumber</code>) contains 304253.3251 (SQL Server example from <a href="http://www.microsoft.com/downloads/details.aspx?familyid=bae8beec-9892-4ecd-a9db-292254895f9c&amp;displaylang=en" rel="nofollow noreferrer">Microsoft White Paper</a>). This is stored in database table <code>AllUserData</code>, column <code>float1</code> of type <code>float</code> (SQL Server 2005). <code>float</code> is an approximate data type.</p> <p>Running the following queries:</p> <pre><code>DECLARE @ListName UNIQUEIDENTIFIER SET @ListName = (SELECT tp_Id FROM AllLists WHERE tp_Title = 'TestList') SELECT CAST(float1 as NUMERIC(18, 11)) AS CustomNumber FROM AllUserData WHERE tp_ListId = @ListName SELECT float1 AS CustomNumber FROM AllUserData WHERE tp_ListId = @ListName </code></pre> <p>Gives the following results:</p> <pre><code>CustomNumber 304253.32510000002 CustomNumber 304253.3251 </code></pre> <p>Creating a calculated column with the formula <code>=CustomNumber*100000000000</code> which might be expected to display the incorrect value of <code>30425332510000002</code> actually <strong>displays the correct (from the user's perspective) value of <code>30,425,332,510,000,000.00000</code></strong>. I assume that this behaviour is due to the code reading the <code>float</code> value from the database doing a cast to <code>numeric</code> with a suitably small number of decimal places and manipulating the values in memory using the .Net Decimal type.</p> <p>There are <a href="http://www.sqlservercentral.com/Forums/Topic544518-9-2.aspx" rel="nofollow noreferrer">suggestions</a>, however, that on SQL Server 2000 calculation errors may manifest in this case since the behaviour of <code>float</code> values has been altered between the versions.</p> <p><strong>Test for money storage and retrieval II</strong></p> <p>Based on the results from the previous test add the following value to the <code>CustomNumber</code> column: 9999999999999999.</p> <p>This 16 significant digit value is <strong>displayed incorrectly in the list (and edit) views as 10,000,000,000,000,000</strong> (using a value with 15 digits displays correctly).</p> <p>Inspecting the <code>AllUserData</code> table shows that the value is stored incorrectly in the database and running the following query:</p> <pre><code>DECLARE @f FLOAT SET @f = 9999999999999999 SELECT CAST(@f as NUMERIC(20, 0)) </code></pre> <p>Gives the result:</p> <pre><code>10000000000000000 </code></pre> <p>Which demonstrates that SQL Server is rounding the number on insertion.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload