your opinion about storing FixedDecimal in Mongo

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

your opinion about storing FixedDecimal in Mongo

Sabine Manaa
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



Reply | Threaded
Open this post in threaded view
|

Re: your opinion about storing FixedDecimal in Mongo

jtuchel
Am 19.08.13 10:38, schrieb Sabine Knöfel:

> 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?
>
>
Hi Sabine,

my misinformed opinion on storing fixed decimals is to completely avoid
floats and keep it as simple as possible. Floats smell like problems to me.
Why not store two integers: one for the integer part and one for the
digits and implement some kind of converter for storing/retrieving.


Joachim



--
-- 
----------------------------------------------------------------------- 
Objektfabrik Joachim Tuchel          mailto:[hidden email] 
Fliederweg 1                         http://www.objektfabrik.de
D-71640 Ludwigsburg     http://joachimtuchel.wordpress.com
Telefon: +49 7141 56 10 86 0         Fax: +49 7141 56 10 86 1


Reply | Threaded
Open this post in threaded view
|

Re: your opinion about storing FixedDecimal in Mongo

jtuchel
Am 19.08.13 10:46, schrieb [hidden email]:

> Am 19.08.13 10:38, schrieb Sabine Knöfel:
>> 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?
>>
>>
> Hi Sabine,
>
> my misinformed opinion on storing fixed decimals is to completely
> avoid floats and keep it as simple as possible. Floats smell like
> problems to me.
> Why not store two integers: one for the integer part and one for the
> digits and implement some kind of converter for storing/retrieving.
>
with "digits" I mean the part after the decimal point. Would decimal
part be a better term? not sure...

>
> Joachim
>
>
>


--
-- 
----------------------------------------------------------------------- 
Objektfabrik Joachim Tuchel          mailto:[hidden email] 
Fliederweg 1                         http://www.objektfabrik.de
D-71640 Ludwigsburg     http://joachimtuchel.wordpress.com
Telefon: +49 7141 56 10 86 0         Fax: +49 7141 56 10 86 1


Reply | Threaded
Open this post in threaded view
|

Re: your opinion about storing FixedDecimal in Mongo

EstebanLM
In reply to this post by Sabine Manaa
Hi,

yes, looks like too much :)
I would go with the float representation... for the conversion, I do not have an experience or opinion about performance or db footprint.

You have to check that in the old empirical fashion way :)

Esteban

On Aug 19, 2013, at 10:38 AM, Sabine Knöfel <[hidden email]> 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
>
>
>
>
>
>
>
> --
> View this message in context: http://forum.world.st/your-opinion-about-storing-FixedDecimal-in-Mongo-tp4704104.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>


Reply | Threaded
Open this post in threaded view
|

Re: your opinion about storing FixedDecimal in Mongo

Henrik Sperre Johansen
In reply to this post by Sabine Manaa

On Aug 19, 2013, at 10:38 , Sabine Knöfel <[hidden email]> 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


signature.asc (859 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: your opinion about storing FixedDecimal in Mongo

Sabine Manaa
Hi Henry, Esteban, Joachim,

thanks for your opinion!

The ranges of my data are relatively small because my application deals with travel expenses, e.g. Hotel receipts, Taxi receipts, Flights et. So, 99,99% of all my amounts are less than 10.000 Euro. 

So I will try it with the Float solution and use a scale of 4.

...and I will indeed add checking for range! Good point, I do not have this yet.

Sabine



On Mon, Aug 19, 2013 at 12:48 PM, Henrik Sperre Johansen [via Smalltalk] <[hidden email]> wrote:

On Aug 19, 2013, at 10:38 , Sabine Knöfel <[hidden email]> 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


signature.asc (859 bytes) Download Attachment



If you reply to this email, your message will be added to the discussion below:
http://forum.world.st/your-opinion-about-storing-FixedDecimal-in-Mongo-tp4704104p4704124.html
To unsubscribe from your opinion about storing FixedDecimal in Mongo, click here.
NAML