INT vs DECIMAL for "Price" column in mysql? -


i saw answers similar questions here , here. seems suggested use decimal type price. however, since price won't go below 1 cent, can use int type price changing unit "dollar" "cent"? e.g $7.99 same 799 cents.

is there advantage choose int on decimal(9,2), regarding storage space, read/write speed, performance when using functions (min, max, sum etc) or other aspects?

i'd recommend representing currency values in smallest applicable unit plain old integer. things dollars means using cents, though on occasions may need use smaller unit. instance of paying out 5% commissions on transactions few cents each rounding otherwise turn them zero. in case using "millicents" might work better.

while fixed-place decimal(9,2) column preserve values faithfully, application platform you're using may not treat them nicely , result in bizarre floating-point behaviour kicking in if you're not careful.

it can little annoying have convert between dollars , internal unit represent them, far less annoying having explain accounting money went missing.

in terms of performance, int values default fastest hands down. they're compact in general terms. if need store values in excess of +/-2.1b, if you're dealing large amounts of dollars, need use bigint. can present problems application scripting language, if not prepared, might render these floats , cause problems.

as always, test code exhaustively large and small values.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -