开发者

solve numeric overflow problem when converting to float

开发者 https://www.devze.com 2023-01-12 14:18 出处:网络
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 wil

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 issu开发者_C百科e. Just need to make the query run.


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.


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.


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


Truncation / Rounding is not an option?

How about NULL instead?

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号