
Practical “byte” sized database tips!
United States
Joined February 2020
- Tweets11
- Following107
- Followers33
- Likes13
Looking for an easy way to check disk space in Microsoft SQL Server? Look no further! https://teapawt.net/t.co/qRtO42qwaE
1
For more info check out these links:
husobee.github.io/money/floa…
stackoverflow.com/questions/…
en.wikipedia.org/wiki/Non-de…
What about non-base-10 currencies you ask? According to Wikipedia there are only 2 in existence and they are only theoretically non-decimal so this advice applies to every currency.
1
Going back to our donut example, this math would then be 12 donuts * 110 cents = 1,320 cents. If we then wanted to display this in $, we would simply divide by 100.0 and format the right number of decimals.
1
Our suggestion: Store the lowest denomination as an integer. For example, with USD storing all money values as cents in an integer column.
1
Another example: Selling 12 gourmet donuts for 1.10 each. In a Python shell the result is 13.200000000000001 which cannot be accurately represented as base-10 without rounding.
1
Floats can't calculate base-10 numbers accurately without rounding. For example Dividing $1 / 3.0 would yield .333333...
1
Naming convention is always a hot topic... We think simplicity and consistency wins out!
#databases #programming #software
1

