Re:Appropriate Uses for SQLite
by haimez on Monday February 12, 2018 @10:23AM
(#16359145)
Yes it is. You convert to a big decimal representation, compute the tax/interest and then intentionally round back to an integer format using the appropriate rounding mode.
[ Parent
| on HN ]
Re:Appropriate Uses for SQLite
by ifdefdebug on Monday February 12, 2018 @10:34AM
(#16359234)
GP didn't say it's impossible, he said it's not worth the trouble which is an opinion statement that can't be countered with "yes it is".
Yes, it can. The case and point is that you need to control where those moments of imprecision happen, and using fixed point a fixed point (often integer/long) representation is absolutely worth the effort because it's not much effort at all and you DEFINITELY care about when your money calculations involved rounding.
Re:Appropriate Uses for SQLite
by fauigerzigerk on Monday February 12, 2018 @11:02AM
(#16359487)
And why would I not prefer to get help from a database system to do that?
If that's the only reason to use a "real" database, then what you have is a 100MB+ multi-process (and potentially costly) library to perform a few calculations.
(I don't disagree with you, just answering your question)
Re:Appropriate Uses for SQLite
by fauigerzigerk on Monday February 12, 2018 @01:03PM
(#16360458)
Of course there are many other considerations, but there is a class of small finance related multi-tenancy systems for which monetary calculations are key and either a database server or a database library can potentially make sense.
Resource consumption isn't an issue at all. 100MB+ is less than loading an average news website in a browser and it costs almost nothing. The reason why I would have wanted to use SQLite sometimes is that it makes it easy to distribute and run the entire app on premises if needed. People are rightly concerned about losing access to web based software.
There are also also many use cases where you don't want to "store" something at all, just compute the value (eg: a shopping cart that is not yet a purchase), and you don't want to to either 1. duplicate implementations or 2. wait for a network request to your database to complete.