kralco626
kralco626

Reputation: 8624

solve numeric overflow problem when converting to float

I have a float value that i need to do some calculations on and insert into a numeric(9,2). However in rare (and likley erronous) cases there are some data anomolies and I end up with a value that will not fit into numeric(9,2).

What is a good solution to this problem? Maybe just use 9999999.99 if the number is 9999999.99 or greater?

Any better ideas (besides of course changing the column data type)

Thanks!

EDIT:

I just wanna make the thing run without error. I can't "correct" the data. I can't omit it because then when I do a sumation there will be no indication that this value is wrong. We are talking a FRACTION of a FRACTION of a percent of the data has this issue. Just need to make the query run.

Upvotes: 1

Views: 1891

Answers (4)

KM.
KM.

Reputation: 103597

this is a business decision! how can I possibly know your application and guess what you should do when there is a problem? If this is an accounting application, round the number up and deposit the money in my account!

You should validate the data before the calculation and stop with a message/error log noting the problem value. Any "fake" value you enter into this column will need to be handled by other code, so don't do that.

Upvotes: 3

Joe Stefanelli
Joe Stefanelli

Reputation: 135818

If you believe the case is erroneous then an error should be raised and the original data used for the calculation should be corrected. Do not mask the original problem and perpetuate the error deeper into your system by trying to store some artificial value.

Upvotes: 4

Beth
Beth

Reputation: 9607

Add an independent overflow field or variable, or introduce an error condition.

Upvotes: 1

Rawheiser
Rawheiser

Reputation: 1218

Truncation / Rounding is not an option?

How about NULL instead?

Having a special data value for that condition doesn't smell right.

Upvotes: 1

Related Questions