On Aug 19, 2013, at 10:38 , Sabine Knöfel <sabine.knoefel@gmail.com> wrote:
Hi,
I am interested in your opinion. I use FixedDecimal for computing currency amounts. This works fine.
When storing the amounts with voyage into mongo (I have a lot of them!!!), normally, one currency amount would be stored into mongo as follows:
"vatAmountEUR": { "#instanceOf": "FixedDecimal", "negative": false, "number": NumberInt(90280), "part1": NumberInt(9), "part2": NumberInt(280), "scale": NumberInt(4) }
I think, this is a lot of stuff for one single value. I tend to convert the FixedDecimal into a Float for storing it. In this case, it would be like this:
"vatAmountEUR": 0.7196
When loading, I immediately re-convert it into a FixedDecimal. I would do NO computing with the float(!!).
What is your opinion about this (rounding issues, performance, database size etc.)? Do you think, there is something against it? What would you do?
Sabine
There are rounding issues even without doing arithmetic, conversion scaled -> float WILL inherently be lossy due to float's fixed size. You are only ensured 15 decimal digits of precision with 64-bit floating point numbers like in Pharo (BSON Doubles): 98765432109.87658s5 asFloat asScaledDecimal: 5 98765432109.87659s5 Though, Compared to using NumberInt ( a signed 32-bit integer, with max 9 digits) for storing the unscaled number, it's actually the better option⦠I guess the morale is, either way, as long as you are storing values in fixed size data fields (and not say, a String), you need some checks in place to ensure the numbers you are saving are within valid ranges. ;) Cheers, Henry