[英]Visual Studio MFC in C++: Why is "int" working but not "double"?
I'm using Visual Studio 2013 to build a UI using the MFC application.我正在使用 Visual Studio 2013 使用 MFC 应用程序构建 UI。 I use "Edit Control" to take three numerical inputs and a button that will produce a dialogue box that states the values of these inputs.
我使用“编辑控件”来获取三个数字输入和一个按钮,该按钮将产生一个对话框,说明这些输入的值。 When the variable from the Edit Control boxes are ints, it works properly.
当编辑控制框中的变量是整数时,它可以正常工作。 When they are doubles, I get 0's for two values and a random value for the third.
当它们是双打时,我得到两个值的 0 和第三个值的随机值。 Here is my code for the button press:
这是我的按钮按下代码:
void CMFCApplication4Dlg::OnBnClickedButton2()
{
UpdateData();
CString temp2;
temp2.Format(_T("The frequency is %d Hz, the pulse width is %d ms, the duration is %d ms"), frequency, pulsewidth, duration);
MessageBox(temp2, 0, MB_ICONINFORMATION);
}
How can I make this work for doubles?我怎样才能使这项工作适用于双打? My finished application will have to do some calculations that require decimals, so ints are not an option.
我完成的应用程序将不得不做一些需要小数的计算,所以整数不是一个选项。 I run into the same problem when I use floats too.
当我使用浮点数时,我也遇到了同样的问题。
This is my first question and I'm not a very good programmer so I apologize if this is trivial.这是我的第一个问题,我不是一个很好的程序员,所以如果这是微不足道的,我深表歉意。
That %d will only work with integers. %d 只适用于整数。 Try
%.2f
.试试
%.2f
。 Excluding that last period.不包括最后一个时期。 That should give you a number with two decimal places, but I haven't googled anything so check my syntax.
这应该给你一个小数点后两位的数字,但我没有用谷歌搜索任何东西,所以检查我的语法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.