MongoDB issue reading value with type double [duplicate]
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
.
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
mongodb mongodb-query
marked as duplicate by Neil Lunn
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.
add a comment |
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
.
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
mongodb mongodb-query
marked as duplicate by Neil Lunn
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
add a comment |
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
.
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
mongodb mongodb-query
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
.
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
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
mongodb mongodb-query
asked Nov 12 '18 at 23:28
LP13
4,6151060132
4,6151060132
marked as duplicate by Neil Lunn
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
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
add a comment |
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
add a comment |
0
active
oldest
votes
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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