C
C#2mo ago
antahra

How to retain precision in the Sql Server Table column data type 'float' when using SqlBulkCopy?

How do I ensure that SqlBulkCopy saves "float" values as given in the datatable instead of saving their approximations? It can be seen in the attachments that Sql Server supports saving the value on using simple insert statements or dapper's dynamic parameters. I want to take advantage of the efficiency of SqlBulkCopy class to save data from a datatable to the SQL Server. Unfortunately changing the database table column data type to "Float(2)" or "Real" is not an option. Only "Float" is allowed for compatabilty reasons. Generally the tool I am working on is used for database versioning purposes. I have alternatives like Dapper's Insert Multiple Rows which is slow compared to SqlBulkCopy. And commercial tools are not an option.
2 Replies
Angius
Angius2mo ago
If you want precision, don't use float
oke
oke2mo ago
float is a 32 bit number, double is 64 bits, and decimal is 128 bits
Want results from more Discord servers?
Add your server