ripper234
ripper234

Reputation: 230048

Should I store doubles or decimals in mysql database?

When does storing doubles make sense? Assuming you read the data off a decimal-notation CSV (e.g. with values such as "5.03"), does it make sense to use mysql's DOUBLE type? Won't there be needless round-off errors?

Upvotes: 3

Views: 2125

Answers (1)

Pablo Santa Cruz
Pablo Santa Cruz

Reputation: 181290

You should use double numbers when you need to store really small or huge numbers. Something like 9.837262 x 10^-567. Other than that, I'd use fixed precision numeric types to avoid the rounding errors you are mentioning.

Nowadays, I don't see "saving space" as a valid reason to use double instead of numeric values, but there can be some very special scenarios where this reason might be valid.

Upvotes: 5

Related Questions