Thanks

I have always used integer's, never floats or doubles, I realised back in the 90's that was a mistake when implementing credit card transactions. Rounding errors bite hard.

I have always decided at the start of a project what was the maximum precision needed, usually 2 decimal places but occasionally more. I can see with kmymoney 4 digits is the best because I believe that is normal for shares. however I don't do shares so I could be wrong.

Just looked it up, shares below $1.00 is to 4 decimal places, 2 places otherwise.

I can see storing it using numerator denominator is more flexible.

Chris

On 15/11/2022 5:42 pm, Thomas Baumgart via KMyMoney-devel wrote:
On Dienstag, 15. November 2022 01:01:03 CET Chris via KMyMoney-devel wrote:

I was going through the database tables when a file was stored as sqlcipher.

I came across something I haven't seen before and I was wondering why it was
that way

Transaction values are stored as text strings but with unusual divisors.

For example the value 18.95 may be stored as "1895/100" which is 1895
divided by 100 = 18.95. All and good

but there are other ones which confuse me as to why its done this way.

Examples are ...

unformatted => formatted
258/25     =>      10.32
124/25     =>     4.96
-273/50    =>      -5.46
1/2            =>     0.5

Can some one explain why it is done that way?
See 
https://stackoverflow.com/questions/3730019/why-not-use-double-or-float-to-represent-currency
for the details of why we use the "numerator/denominator" representation.

The ones that confuse you are simply canceled to the smallest denominator. 
That's a
feature/requirement of the underlying library.

124/25     =>     4.96
124/25 * 4/4 => 496/100

Reply via email to