Sam
Sam

Reputation: 545

Arithmetic overflow error converting numeric to data type numeric while saving decimal

I'm trying to save decimal value in DB but getting this error.

The value I'm trying to save 0.00038711029163348665 or 1.00038711029163348665 or 2.00038711029163348665, and column in DB is Decimal(18,18) not sure what I'm doing wrong

Upvotes: 0

Views: 50

Answers (2)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521409

The precision DECIMAL(18,18) means 18 total units of precision, all 18 of which come after the decimal point. You need at least one unit of precision to the left of the decimal point to handle the whole number components of the input, so you should be using DECIMAL(19,18), or something similar.

See the demo to verify that DECIMAL(19,18) resolves your problem, at least for the data you showed us.

Upvotes: 3

Gordon Linoff
Gordon Linoff

Reputation: 1269933

Decimal(18,18) has 18 digits to the right of the decimal place and none to the left, so 1.00038711029163348665 doesn't fit.

Use a larger type. Why not just use decimal(38, 18)?

Upvotes: 2

Related Questions