I have this fintech application (written in Ruby with some JS micro-services) which stores transactions in a database table, amounts are stored as integers in cents, eg $123.45 is stored as 12345, -Є56.78 is stored as -5678. The transactions table currently has about 400 million entries across all partitions. Amounts are typically under 4 digits with under 1% being over 4 digits and under 0.1% over 6 digits.
This has worked pretty well for me for a number of years but now I am facing two issues:
- some amounts in a few specific currencies can't be stored eg Rials since $1 would be about 45000 Rials, so far I just didn't offer support for these currencies and it caused some loss of business.
- for the same reason can't store amounts in a large number of cryptocurrencies/tokens including Bitcoins
The time has come to sort this out...hopefully without breaking any of the Ruby or JS applications as I know both languages and also the database will have some issues with floating point numbers.
What data type should I use to store these amounts?
t.decimalfor RoR but ruby reads it as a string. You will have to handle that in your code.