1

I got a problem with function bson_append_double below:

dvalue = 0.01; bson_append_double(pbson, field_name, -1,(double)dvalue); 

but the result i got is annoying long: 0.0099999997764825820923 Did anyone faced this problem before, please help me. Thanks and Regards

2
  • What output are you expecting? Commented May 29, 2017 at 5:28
  • Same as input 0.01. Can it be? Commented May 29, 2017 at 7:16

1 Answer 1

0

this is simply a float-to-double conversion. If you don't want to lose the precision, you'll need to declare the variable as a double in the first place.

somewhere in your code you have a line

float dvalue; 

if you are able to promote to type double you should consider changing the declaration to:

double dvalue; 

here is a previous question on loss of precision in conversions.

Precision loss from float to double, and from double to float?

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.