C ++ MFC double to CString [英] C++ MFC double to CString

查看:151
本文介绍了C ++ MFC double to CString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对我的英语很抱歉。

我需要将double值转换为CString,因为我需要做AfxMessageBox(double_value);

I need to convert double value to CString, because i need to do AfxMessageBox(double_value);

我发现这个:

std::ostringstream ost;
ost << double_value;
std::cout << "As string: " << ost.str() << std::endl;
//AfxMessageBox(ost.str()); - Does not work.

我该如何做?

推荐答案

AfxMessageBox 需要一个 CString 对象,因此将double格式化为 CString 并传递:

AfxMessageBox expects a CString object, so format the double into a CString and pass that:

CString str;
str.Format("As string: %g", double);
AfxMessageBox(str);

编辑:如果希望将值显示为整数(小数点后没有值)

If you want the value displayed as an integer (no value after decimal point) then use this instead:

str.Format("As string: %d", (int)double);

这篇关于C ++ MFC double to CString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆