|
Boost Users : |
From: Tom Bachmann (e_mc_h2_at_[hidden])
Date: 2007-04-01 05:03:56
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Digvijoy Chatterjee schrieb:
> ...
> here is a simple program,
> int main() {
> double d=76.32;
> std::string s = boost::lexical_cast<std::string>(d);
> cout << s << endl;
> }
>
> output
> 76.319999999...
>
> a) am i doing something wrong ??
I don't think so.
> b) if this is not wrong s this standard behavior ??
>
I'd say so. Due to the binary representation not all numbers with a
representation of a fixed amount of digits in our decimal system have
such a representation in the computer. Lexical_cast internally uses
standard streams, if they don't correct such things (and I don't know of
any implemementation that'd do so), your output will look garbaged. Try
adding std::cout << d << std::endl.
- --
- -ness-
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFGD3V8vD/ijq9JWhsRAqaBAJ9bIJh5erQWZcPGz3Xbgl1xsqtVsACfc2R4
eJj/WLx3HHGkOcahvg7reyg=
=zDxW
-----END PGP SIGNATURE-----
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net