D_D
D_D

Reputation: 1059

Decimal or Float (SQL Server and C++)

What is the best way to store 17 decimals (ex. 1.12345678901234567) in a column table in SQL server?

Also which type should I use in C++ to be able to push these 17 decimals into the SQL Query?

Thanks

Upvotes: 0

Views: 1192

Answers (2)

Ariel
Ariel

Reputation: 26783

You actually seem to have 18 digits there (including the integer part). You would need a 128 bit float to store this, see: http://en.wikipedia.org/wiki/Quadruple_precision_floating-point_format (80 bits would work too, if you have access to such a CPU. See: http://en.wikipedia.org/wiki/Extended_precision)

To read and store decimal types in C++ you would need to store them as strings. I would look for a GMP math library. (Arbitrary precision math library.)

You will need to give more detail about where the numbers come from to get better advice.

Do you really need exact digits?

Upvotes: 1

Jacob
Jacob

Reputation: 43299

For your SQL Server column, use Decimal. You can specify the percision exactly (17 decimals).

Upvotes: 1

Related Questions