1

I was wondering what's the best data type for transaction amounts (in euro) of a bank ? Example : The person "A" sends 120.59 euros to "B"

What's the best data type to store this data (120.59) in a database ? the transaction amount is positive, 2 digits after the decimal, and it will be used in calculations after (sum of amounts, averages, variance and standard-deviations...etc). Is it okey to use REAL ? DECIMAL is ok ?

Otto
  • 145
  • 1
  • 2
  • 6

1 Answers1

2

You do not want to store monetary amounts using floating point numbers.

You want to store them using fixed point -- that is numeric/decimal. For your example, it would be something like numeric(10, 2). However, you might want fractions of a cent for some reason, so larger precision and scale such as numeric(20, 4) is a good idea.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786