Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I will answer your question partially (because I do not know much about C#).</p> <p><strong>So what will you lose if you will store decimals as strings.</strong></p> <ul> <li>your numbers on average would weight more (each double number <a href="http://bsonspec.org/#/specification">cost 8 bytes to store</a> which means that every string that has more then 8 chars will weight more). Because of these your indexes (if they will be built on this field would grow)</li> <li>you will not be able to use operators which takes numbers as arguments <a href="http://docs.mongodb.org/manual/reference/operator/update/inc/#up._S_inc">$inc</a>, <a href="http://docs.mongodb.org/manual/reference/operator/update/bit/#up._S_bit">$bit</a>, <a href="http://docs.mongodb.org/master/reference/operator/query/mod/#op._S_mod">$mod</a>, <a href="http://docs.mongodb.org/master/reference/operator/update/min/#up._S_min">$min</a>, <a href="http://docs.mongodb.org/master/reference/operator/update/max/#up._S_max">$max</a> and in 2.6 version <a href="http://docs.mongodb.org/master/reference/operator/update/mul/#up._S_mul">$mul</a>. (May be I forgot something)</li> <li>you will not be able to compare numbers (may be '1.65' and '1.23' is comparable as a string, but definitely not numbers with e and minuses somewhere in between). Because of this operations which build on top of comparison like <a href="http://docs.mongodb.org/manual/reference/method/cursor.sort/">$sort</a>, and all these <a href="http://docs.mongodb.org/manual/reference/operator/query/gt/">$gte, $gt, $lte, $lt</a> will not work correctly.</li> </ul> <p><strong>What will you lose in precision if you store decimal as double</strong>:</p> <ul> <li>based on <a href="http://msdn.microsoft.com/en-us/library/364x0z75.aspx">this, Decimal in C#</a> has 28-29 significant digits, whereas looking at my first link and checking the <a href="http://en.wikipedia.org/wiki/Double-precision_floating-point_format#IEEE_754_double-precision_binary_floating-point_format%3a_binary64">spec for double precision</a> you see that it has 15-17 significant digits. This is basically what you will lose</li> <li>another really important thing which people sometimes forget when dealing with double floats is illustrated below:</li> </ul> <p>.</p> <pre><code>db.c.insert({_id : 1, b : 3.44}) db.c.update({_id : 1},{$inc : {b : 1}}) db.c.find({b: 4.44}) // WTf, where is my document? There is nothing there </code></pre> <p><strong>Regarding the 2-nd subquestion:</strong> </p> <blockquote> <p>Is there a way to set a default serialization of decimals as double (AllowTruncation) without having to put an Attribute on each property?</p> </blockquote> <p>I do not really understood it, so I hope someone would be able to answer it.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload