Subj : Re: Need help with converting float to string To : borland.public.cpp.borlandcpp From : Sebastian Ledesma Date : Fri May 21 2004 06:06 pm Jeff: I tipically use sprintf: data = (low_byte + 256 * (char) high_byte) / 100.0; sprintf (string, "%f05.2", data); Saludos Sebastian "Jeff Baker" escribió en el mensaje news:40ae58aa@newsgroups.borland.com... > I need some help. The function listed below compiles and works but the > format it displays is not the kind I need. This function displays "data" in > exponential format and I need it to be in decimal format and no suppression > of trailing zeros. The ecvt() and fcvt() functions do exactly what I'm > looking for, however neither of these functions insert the decimal in the > string. Does anyone have an idea on how to get this done? > > Note: the data is alway in x.xx format. > > [start of code] > #include > #include > > void DisplayData(HWND hwnd,BYTE low_byte,BYTE high_byte) > { > char string[255],label[]="Data"; > float data; > HDC hdc; > RECT rect; > rect.left = 210; rect.top = 10; rect.right = 340; rect.bottom = 23; > HBRUSH back_color = (HBRUSH)GetStockObject(BLACK_BRUSH); > COLORREF text_color = RGB(127,255,127); > HFONT hfnt,hOldFont; > hdc = GetDC(hwnd); > SetTextColor(hdc,text_color); > SetBkMode(hdc,TRANSPARENT); > hfnt = (HFONT)GetStockObject(SYSTEM_FONT); > hOldFont =(HFONT)SelectObject(hdc,hfnt); > if (hOldFont) > { > FillRect(hdc,&rect,back_color); > TextOut(hdc,rect.left,rect.top,label,strlen(label)); > data = (FLOAT)((low_byte + (256 * high_byte)) / pow10(2)); > gcvt(data,4,string); > TextOut(hdc,rect.left+80,rect.top,string,strlen(string)); > SelectObject(hdc,hOldFont); > } > UpdateWindow(hwnd); > ReleaseDC(hwnd,hdc); > } > [end of code] > > .