c# - Decimal out of range exception -
in c# application, trying save decimal price sql server table. columns type decimal
no total digits defined.
without discount calculations, works fine.
but when run calculations, final value of 21800
, , following error when trying save it.
"parameter value '218000/00000000000000' out of range."
i don't understand zeros come from! thing know myvalue.tostring()
218000/00000000000000
, too!
i understand digits after floating point caused calculations. whatever do, value 21800
when watching it. why trying save 218000/00000000000000
? why care @ zeros?
any ideas why happens , how fix it?
there 2 ways store decimal numbers:
fixed-point: have defined in sql server project. defined
decimal (19,4)
, means 19 digits total , 4 digits after decimal point. if define such type, every number always has 4 digits after decimal point; , also, cannot store number more 4 digits after decimal point. and note, there no equivalent fixed point in c#!floating point: these types
float
,double
,decimal
in c#, , typefloat(n)
in sql server. in floating point, names says, can vary number of digits before , behind decimal point. (technically, have fixed number of digits, so-called mantissa, , can move decimal point around 2nd number, exponent)
so project: in database, use fixed point, while in c#, have floating point. therefore, when calculate in c#, , want store in database, converted floating point fixed point. however, if number in c# not fit decimal numbers in database, out of range error.
Comments
Post a Comment