i have a requirement where i don't want json library to round the values of double datatype. Is there we can prevent it ?
e.g.
when i call "json.dump" function on my double variable "Amount" it gets rounded values instead of actual values.
- The Actual value Amount = 2555.5599999999999 gets rounded to 2555.56
- The Actual value Amount = 2527.7800000000002 gets rounded to 2527.78
is there any way we can stop rounding ?
code looks like
struct PaymentInfo
{
double Amount;
std:string Currency ;
};
I have implemented "to_json" function for the above structure.
in the main function , i do following.
main()
{
PaymentInfo Pay_obj ;
Pay_obj.Amount = 2555.5599999999999;
Pay_obj.Currency = "USD";
json json_obj = Pay_obj;
std:: stringstream output;
output << json_obj.dump(); // after this statement the value of Amount gets rounded to 2555.56.
// i want to retain the original value as it is. is there a way we can to
// it.
}
i have a requirement where i don't want json library to round the values of double datatype. Is there we can prevent it ?
e.g.
when i call "json.dump" function on my double variable "Amount" it gets rounded values instead of actual values.
is there any way we can stop rounding ?
code looks like
struct PaymentInfo
{
double Amount;
std:string Currency ;
};
I have implemented "to_json" function for the above structure.
in the main function , i do following.
main()
{
PaymentInfo Pay_obj ;
Pay_obj.Amount = 2555.5599999999999;
Pay_obj.Currency = "USD";
json json_obj = Pay_obj;
std:: stringstream output;
output << json_obj.dump(); // after this statement the value of Amount gets rounded to 2555.56.
// i want to retain the original value as it is. is there a way we can to
// it.
}