Arithmetic operation resulted in an overflow. (Add

2019-01-27 12:40发布

I can't understand this error:

In this call to method SetVolume, Volume = 2055786000 and size = 93552000. Volume is an Integer property, and size is also Integer, as you can see.

The class is a partial class of a dbml entity class, however this Volume property is NOT a column in the database, it exist only in the partial class, as a "business object property".

View Detail shows:

Data > Item : In order to evaluate an indexed property, the property must be qualified and the arguments must be explicitly supplied by the user.

alt text

What may cause this...?

8条回答
smile是对你的礼貌
2楼-- · 2019-01-27 12:43

2055786000 + 93552000 = 2149338000, which is greater than 2^31. So if you're using signed integers coded on 4 bytes, the result of the operation doesn't fit and you get an overflow exception.

查看更多
叼着烟拽天下
3楼-- · 2019-01-27 12:45

Maximum value fo int is 2147483647, so 2055786000+93552000 > 2147483647 and it caused overflow

查看更多
倾城 Initia
4楼-- · 2019-01-27 12:50
int.MaxValue = 2147483647
2055786000 + 93552000 = 2149338000 > int.MaxValue

So you cannot store this number into an integer. You could use Int64 type which has a maximum value of 9,223,372,036,854,775,807.

查看更多
疯言疯语
5楼-- · 2019-01-27 12:52

This error occurred for me when a value was returned as -1.#IND due to a division by zero. More info on IEEE floating-point exceptions in C++ here on SO and by John Cook

For the one who has downvoted this answer (and did not specify why), the reason why this answer can be significant to some is that a division by zero will lead to an infinitely large number and thus a value that doesn't fit in an Int32 (or even Int64). So the error you receive will be the same (Arithmetic operation resulted in an overflow) but the reason is slightly different.

查看更多
再贱就再见
6楼-- · 2019-01-27 12:54

The maximum size for an int is 2147483647. You could use an Int64/Long which is far larger.

查看更多
ら.Afraid
7楼-- · 2019-01-27 13:09

The result integer value is out of the range which an integer data type can hold.

Try using Int64

查看更多
登录 后发表回答