views:

421

answers:

3

I'm working on a java application,use double type to save value of unitprice,qty etc.I found some of these values show in MSSQL are NAN and throws infinite error when I try to reuse it.This is so unreasonable,I can save it but can not use it anymore!I think the NAN value in MSSQL must be valid when it first presence in java,so i can save.How and when this issue happen?

+3  A: 

You should never use double or float to store prices. Use Decimal instead. Double and float datatypes are not really precise.

FLOAT and REAL data types are both approximate number data types for use with floating point numeric data. Floating point data is approximate; not all values in the data type range can be precisely represented.

Frederik Gheysels
A: 

NaN values are often the result of dividing by zero - this would be the first thing I'd check for.

Cebjyre
A: 

But if it caused by dividing by zero,there is no way to save it,isn't it?