简体   繁体   中英

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);
}

例子

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM