wsprintf怎么扫double值?

damo_xu 2009-08-02 08:49:37
WCHAR tmp[100];
double value = -41.999;
wsprintf(tmp, TEXT(" res: %f"), value);
SetWindowText(hCtrlStatic, tmp);

怎么也扫不到tmp里面,晕!!!最近看不了msdn,郁闷,是不是没有XP及时更新?
如果我想得到 -42怎么办?

如果是 -41.0000003,我想得到-41怎么办? 多谢了。
...全文
1739 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
yanng123456 2012-09-27
  • 打赏
  • 举报
回复
WCHAR tmp[100];
double value = -41.009;
swprintf(tmp, "%f", value);
szuzsq 2012-03-09
  • 打赏
  • 举报
回复
wsprintf和swprintf是不同的
1个是stl的,1个是mfc的,swprintf可以有%f
Rin_2011 2011-07-03
  • 打赏
  • 举报
回复
好,学习了~~~
wujianhuagood 2011-06-25
  • 打赏
  • 举报
回复
嘻嘻 swprintf那格式怎么写呢
linguistics_jl 2010-08-11
  • 打赏
  • 举报
回复
我用VC6也出现了这个问题,就不发帖子问了,
damo_xu 2009-08-02
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 togoblime 的回复:]
wsprintf只能输出字符,字符串和整型数据,要输出任意类型应该用swprintf

The type characters that appear after the last optional format field determine whether the associated argument is interpreted as a character, a string, or a number.
[/Quote]

另一个贴接分!
togoblime 2009-08-02
  • 打赏
  • 举报
回复
wsprintf只能输出字符,字符串和整型数据,要输出任意类型应该用swprintf

int wsprintf(
LPTSTR lpOut,
LPCTSTR lpFmt,
...
);
Remarks
A format specification has the following form:

%[-][#][0][width][.precision]type

The type characters that appear after the last optional format field determine whether the associated argument is interpreted as a character, a string, or a number.
damo_xu 2009-08-02
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 loneking2001 的回复:]
错了,不需要ceil。
C/C++ code WCHAR tmp[100];double value=-41.009;
swprintf(tmp, TEXT(" res: %.0f"), value);
[/Quote]

多谢多谢,满分!!!
可惜看不了msdn,兄台可否再随便解释下这个%.0f和为什么不要用wsprintf?
看书说wsprintf是windows下的版本,但是干什么用的呢?
rayw0ng 2009-08-02
  • 打赏
  • 举报
回复
错了,不需要ceil。
	WCHAR tmp[100]; 
double value = -41.009;
swprintf(tmp, TEXT(" res: %.0f"), value);
rayw0ng 2009-08-02
  • 打赏
  • 举报
回复
	WCHAR tmp[100]; 
double value = -41.999;
swprintf(tmp, TEXT(" res: %.0f"), ceil(value));
xiaogang_1 2009-08-02
  • 打赏
  • 举报
回复
MFC里
CString str;
double value = -41.999;
str.Format("res:%0.0f", value );
SetDlgItemText(id, LPCTSTR(str));
xiaogang_1 2009-08-02
  • 打赏
  • 举报
回复
MFC里
CString str;
str.Format("res:%0.0f",-41.999);
SetDlgItemText(id, -41.999);
xiaogang_1 2009-08-02
  • 打赏
  • 举报
回复
MFC里
CString str;
str.Format("res:%0.3f",-41.999);
SetDlgItemText(id, -41.999);

15,978

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧