What is decimal of SQL Server in MongoDB

primarly i have decimal(13,4) in sqlserver, so what should i keep in mongodb.
secondly if i use double in mongodb what should i keep in c#
and if i keep decimal in mongodb then what should i keep in c#

yours sincerley

Hi Rajesh,

For available data types in MongoDB, please refer to BSON Types. The C#/.NET driver provides equivalent BsonType representations.

The equivalent MongoDB data type is Decimal128.

Double.

Decimal128.

If your use case for floating point values requires precision (such as monetary data), you will want to use Decimal128. Doubles are subject to floating point accuracy problems.

Regards,
Stennie

1 Like
  1. i have used double in mongo, which is already set , so i can not change it.
    and my precision and scale is (13,8) so iT should not create any problem? pls correct me if i am wrong.

2)and in c# i have used decimal , so i think it will not create problem. because we get data from mongo which is quite small.? please correct me if i am worng.

  1. i have used decmal in c# because i also get some data in same class from sqlserver where i have decimal.

yours sincerley

What is this data used for? For example, is it monetary data? And, what kind arithmetic is performed on this data? These aspects can affect how the data is to be defined and handled.

it is length of many bridges like 300.56789345 meters.
and it is used for sum and division to get the percentage of job done.

The input to your application has data defined as two data types, and your application uses them as only one data type. And, you are also saying, that changing the data type at the input to same type is not there.

I think, it depends upon you application and user needs how you work with your data. Since, you know the input and the resulting output, you have to figure whether it works correctly for your needs or not.

For instance, if the calculated final result is not accurate enough for your users with the present data types, what will you consider?

as u can see the input of sql server is 13,4 this is what we will enter in double of mango also. so input is quite smaller than double precision. and decimal which is in c# it has much bigger precision than the double of mongo or the entered 13,4. so this is were u have correct me if i am wrong .

i am not asking about the calculation we do in c# after getting data from sql server and mongo.

q1) so if i enter any thing less than 999999999.9999 then double of mongo will not change it ?
q2) and what ever is in double of mongo will come as it is in decimal of c#

yours sincerley

The decimal BSON type uses the IEEE 754 decimal128 decimal-based floating-point numbering format. Unlike binary-based floating-point formats (i.e., the double BSON type), decimal128 does not approximate decimal values and is able to provide the exact precision required for working with monetary data.

From the mongo shell decimal values are assigned and queried using the NumberDecimal() constructor.

my question was different. I asked in a given situation , what could happen.

i am just asking what i have though is correct or not.

i mean the standards u have written is fine.

but the solution i have given u in this situation is correct or not that is the question.
else i know that i have to research a lot to get to the roots, but i do not have time and experience. that is why i have asked.