PDA

View Full Version : how to use FLOATTOWSTR


ngotl
08-15-2002, 02:09 PM
Hi, i have a float value needed to be stored into database. i guess i cannot use the type dw for the field so i try to convert the float value into string and store it. But when i call FLOATTOWSTR function, it doesnot return the same string as the value of the float variable. Here is my code:


AECHAR* temp;
double x;


temp = (AECHAR*)MALLOC(sizeof(AECHAR*) * 8); // my floating
point has at most 6 digits

if(temp == NUL)
return FALSE;

if(FLOATTOWSTR(x, temp, sizeof(AECHAR*) * 8) == FALSE)
return FALSE;



Now, if x == 10.12, then the string temp should be "10.12" but it is not. when i called string compare function to compare with a wide string "10.12", the result is not equal. I thought it shuold be very straigt forward since it's just a call to a function. Am i missing some tiny thing here? Thanks for any suggestion.
Luong

Murray Bonner
08-15-2002, 05:02 PM
FLOATTOWSTR() right justifies the floating point in the string, padding on the left with space characters. The spaces are the reason WSTRCMP() doesn't give you the result you expect.
Regards,
MB

Murray Bonner
08-16-2002, 02:21 PM
The attached file contains a function I wrote to get rid of the leading spaces.

I don't know if there's an easier way to accomplish the same result.

Hope this helps.
MB