samedi 19 mai 2018

How convert string to double keeping the exact same number represented in the string

The code below would result in moneyDouble = 365.24567874299998 and I need it to be exactly 365.245678743
I wouldn't mind having to set a precision and getting some extra zeros to the right.
This number is used to calculate money transaction so it needs to be exact.
Thanks.

std::string money ("365.245678743");
std::string::size_type sz;     // alias of size_t

double moneyDouble = std::stod (money,&sz);

Aucun commentaire:

Enregistrer un commentaire