Created
June 13, 2017 05:38
-
-
Save neomantra/a3ae147b5040d63daf1a606080cfa97c to your computer and use it in GitHub Desktop.
BSON Float test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// cc -o bson_float_test bson_float_test.c -lbson-1.0.0 | |
#include <stdio.h> | |
#include <libbson-1.0/bson.h> | |
int main(int argc, const char* argv[]) | |
{ | |
bson_t b; | |
bson_init(&b); | |
double dvalue = 0.01; | |
printf("double: %0.20f\n", dvalue); | |
bson_append_double(&b, "double", -1, dvalue); | |
float fvalue = 0.01f; | |
printf("float: %0.20f\n", fvalue); | |
bson_append_double(&b, "float_cast", -1, (double)fvalue); | |
char* json = bson_as_json(&b, NULL); | |
printf("%s\n", json); | |
bson_free(json); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result: