Converting textbox string to float?(将文本框字符串转换为浮点数?)
问题描述
我基本上是在尝试在 Visual Studio 2008 中编写一个基本的转换器,我有 2 个文本框,一个用于获取用户的输入,一个用于输出结果.当我按下按钮时,我希望第一个文本框中的输入乘以 4.35,然后显示在第二个文本框中.到目前为止,这是我在按钮代码中的代码:
I'm basically trying to write a basic converter in visual studio 2008, and I have 2 text boxes, one which gets input from the user, and one which gives output with the result. When I press the button I want the input from the first textbox to multiply by 4.35 then display in the 2nd textbox. This is my code in the button code so far:
String^ i1 = textBox1->Text;
float rez = (i1*4.35)ToString;
textBox2->Text = rez;
但是我遇到了这些错误:
However I'm getting these errors:
f:microsoft visual studio 9.0projectshellowinhellowinForm1.h(148) : error C2676: binary '*' : 'System::String ^' does not define this operator or a conversion to a type acceptable to the predefined operator
f:microsoft visual studio 9.0projectshellowinhellowinForm1.h(148) : error C2227: left of '->ToString' must point to class/struct/union/generic type
f:microsoft visual studio 9.0projectshellowinhellowinForm1.h(149) : error C2664: 'void System::Windows::Forms::Control::Text::set(System::String ^)' : cannot convert parameter 1 from 'float' to 'System::String ^'
请帮助我发疯了,从 C++ 中的文本框获取一些输入是多么可笑的困难.我已经用谷歌搜索了我遇到的所有错误,但没有发现任何有用的信息,我已经搜索了一个小时的答案,请帮忙.
Please help I'm going insane on how ridiculously difficult it is to get some input from a textbox in C++. I've googled every error I had and nothing useful came up, I've been searching answers for an hour already, please help.
推荐答案
为你解决,
String^ i1 = textBox1->Text;
float rez = (float)(Convert::ToDouble(i1)*4.35);
textBox2->Text = rez.ToString();
基本上,您希望将字符串转换为实际数字,进行数学运算,然后将其重新转换为字符串以进行显示.
Basically, you want to convert your string to an actual number, do the math, and then make it back into a string for displaying purposes.
这篇关于将文本框字符串转换为浮点数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将文本框字符串转换为浮点数?


基础教程推荐
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07