解决wsprintf不支持浮点数据的方案

来源:互联网 发布:c语言循环移位指令 编辑:程序博客网 时间:2024/06/02 13:12

我们经常用wsprint去转换数据转换为字符串(我们也可以用_wtof,_wtoi进行反向转换),但是wsprintf却不支持浮点数据的转换,解决方案如下:

 

#include<atlstr.h>

float lf_PriceAfterDiscount=12.3;

WCHAR szPriceAfterDiscount[256];

CString str; 

str.Format(L"%f", lf_PriceAfterDiscount);  
wsprintf(szPriceAfterDiscount, L"%s元",str.GetBuffer(str.GetLength())); 

 

原创粉丝点击