formatting of currency values in kmmsplits table

Thomas Baumgart thb at net-bembel.de
Tue Nov 15 07:12:28 GMT 2022


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

-- 

Regards

Thomas Baumgart

-------------------------------------------------------------
My software never has bugs.
It just develops random features ... -- anonymous
-------------------------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 868 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kmymoney-devel/attachments/20221115/59ab09e1/attachment.sig>


More information about the KMyMoney-devel mailing list