Search code examples
c#.netdapper

double value Dropping scale value after saving to MS SQL using Dapper DynamicParameters


I am missing a scale (see example image below). Even though I specified the precision and scale in my dynamic parameter, I am still loosing the last non zero value.

Not sure what I missed out to do.

const string insertSql = @"insert into DATATABLE (FEES_VALUE) VALUES (@DataValue)";
var doubleValue = 0.06930846118065210000;
var parameters = new DynamicParameters();
parameters.Add("DataValue", doubleValue, dbType: DbType.Decimal, precision: 28, scale: 20);

using (var conn = new SqlConnection(connectionstring))
{
    var data = conn.Execute(query, parameters, commandType: CommandType.Text, commandTimeout: 600);
}

Example

UPDATE: Apparently, it was not a Dapper issue. It was the data type that I used. Below are the results after I tested in more detail (Thanks Cameron for suggesting)

as decimal 0.00058235001858449700
as double 0.00058235001858450000


Solution

  • Changing the data type to decimal instead of double solved my problem