470,870 Members | 1,069 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,870 developers. It's quick & easy.

float to CString conversion not exact

For a reason i don't know, if i convert a float to a cstring, it does not convert to an exact value for all values except round numbers or 1/2 numbers;

the following code (used to convert and later show as text in a MFC Document)
Expand|Select|Wrap|Line Numbers
  1. char buffer1[_CVTBUFSIZE];
  2. _gcvt(i_A11, 12, buffer1);
  3. CString SA11 = (CString) buffer1;
float i_A11 = 1,2 and once converted to Cstring SA11 = "1.20000004768"
float i_A11 = 1,0 and once converted to Cstring SA11 = "1."
float i_A11 = 1,5 and once converted to Cstring SA11 = "1.5"

thanks in advance for the help!
Feb 12 '08 #1
1 4452
11,448 Expert 8TB
Read What every computer scientist should know about floating-point arithmetic.

kind regards,

Feb 12 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

54 posts views Thread by Andy | last post: by
5 posts views Thread by Paul | last post: by
15 posts views Thread by Kay Schluehr | last post: by
16 posts views Thread by Enekajmer | last post: by
116 posts views Thread by Dilip | last post: by
13 posts views Thread by Shirsoft | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.