MongoDB issue reading value with type double [duplicate]










0















This question already has an answer here:



  • How to use decimal type in MongoDB

    2 answers



  • Is floating point math broken?

    28 answers



In mongo I have amount stored as 4.77 with type double.



enter image description here



I am using mongo's C# driver to read the Bson document



 var collection = _mongoDatabase.GetCollection<BsonDocument>("mycollection");
var filter = Builders<BsonDocument>.Filter.Eq("_id", id);
await collection.Find(filter)
.ForEachAsync(document =>

var val = document.GetValue("amount");
);


However, it reads the value as 4.7699999999999996



enter image description here










share|improve this question













marked as duplicate by Neil Lunn mongodb
Users with the  mongodb badge can single-handedly close mongodb questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 12 '18 at 23:40


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • That's what actually is stored inside the computer. You can't store all decimal float numbers in binary format. Modern computers have approximately 10^-16 accuracy for 8byte (double) type so what you are getting is expected behaviour. The reason you can see the number 4.77 correctly on the GUI database explorer is because of rounding when the number is displayed.
    – itsundefined
    Nov 12 '18 at 23:34















0















This question already has an answer here:



  • How to use decimal type in MongoDB

    2 answers



  • Is floating point math broken?

    28 answers



In mongo I have amount stored as 4.77 with type double.



enter image description here



I am using mongo's C# driver to read the Bson document



 var collection = _mongoDatabase.GetCollection<BsonDocument>("mycollection");
var filter = Builders<BsonDocument>.Filter.Eq("_id", id);
await collection.Find(filter)
.ForEachAsync(document =>

var val = document.GetValue("amount");
);


However, it reads the value as 4.7699999999999996



enter image description here










share|improve this question













marked as duplicate by Neil Lunn mongodb
Users with the  mongodb badge can single-handedly close mongodb questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 12 '18 at 23:40


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • That's what actually is stored inside the computer. You can't store all decimal float numbers in binary format. Modern computers have approximately 10^-16 accuracy for 8byte (double) type so what you are getting is expected behaviour. The reason you can see the number 4.77 correctly on the GUI database explorer is because of rounding when the number is displayed.
    – itsundefined
    Nov 12 '18 at 23:34













0












0








0








This question already has an answer here:



  • How to use decimal type in MongoDB

    2 answers



  • Is floating point math broken?

    28 answers



In mongo I have amount stored as 4.77 with type double.



enter image description here



I am using mongo's C# driver to read the Bson document



 var collection = _mongoDatabase.GetCollection<BsonDocument>("mycollection");
var filter = Builders<BsonDocument>.Filter.Eq("_id", id);
await collection.Find(filter)
.ForEachAsync(document =>

var val = document.GetValue("amount");
);


However, it reads the value as 4.7699999999999996



enter image description here










share|improve this question














This question already has an answer here:



  • How to use decimal type in MongoDB

    2 answers



  • Is floating point math broken?

    28 answers



In mongo I have amount stored as 4.77 with type double.



enter image description here



I am using mongo's C# driver to read the Bson document



 var collection = _mongoDatabase.GetCollection<BsonDocument>("mycollection");
var filter = Builders<BsonDocument>.Filter.Eq("_id", id);
await collection.Find(filter)
.ForEachAsync(document =>

var val = document.GetValue("amount");
);


However, it reads the value as 4.7699999999999996



enter image description here





This question already has an answer here:



  • How to use decimal type in MongoDB

    2 answers



  • Is floating point math broken?

    28 answers







mongodb mongodb-query






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 12 '18 at 23:28









LP13

4,6151060132




4,6151060132




marked as duplicate by Neil Lunn mongodb
Users with the  mongodb badge can single-handedly close mongodb questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 12 '18 at 23:40


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Neil Lunn mongodb
Users with the  mongodb badge can single-handedly close mongodb questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 12 '18 at 23:40


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • That's what actually is stored inside the computer. You can't store all decimal float numbers in binary format. Modern computers have approximately 10^-16 accuracy for 8byte (double) type so what you are getting is expected behaviour. The reason you can see the number 4.77 correctly on the GUI database explorer is because of rounding when the number is displayed.
    – itsundefined
    Nov 12 '18 at 23:34
















  • That's what actually is stored inside the computer. You can't store all decimal float numbers in binary format. Modern computers have approximately 10^-16 accuracy for 8byte (double) type so what you are getting is expected behaviour. The reason you can see the number 4.77 correctly on the GUI database explorer is because of rounding when the number is displayed.
    – itsundefined
    Nov 12 '18 at 23:34















That's what actually is stored inside the computer. You can't store all decimal float numbers in binary format. Modern computers have approximately 10^-16 accuracy for 8byte (double) type so what you are getting is expected behaviour. The reason you can see the number 4.77 correctly on the GUI database explorer is because of rounding when the number is displayed.
– itsundefined
Nov 12 '18 at 23:34




That's what actually is stored inside the computer. You can't store all decimal float numbers in binary format. Modern computers have approximately 10^-16 accuracy for 8byte (double) type so what you are getting is expected behaviour. The reason you can see the number 4.77 correctly on the GUI database explorer is because of rounding when the number is displayed.
– itsundefined
Nov 12 '18 at 23:34












0






active

oldest

votes

















0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

政党

天津地下鉄3号線