如何将浮动值插入文本框 [英] how to insert afloat value into a textbox

查看:51
本文介绍了如何将浮动值插入文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,哈罗,
如果想给文本框浮动值,那该怎么办
如果我有这些
,以供讲解

Hallo every one,
if iwant to give a textbox afloat value how can ido that
for examble if ihave these

int p,q;
float a,b,c,d;
a=float.parse(textbox1.text);
b=float.parse(textbox2.text);
if(p<q)
{
c=a;
d=b;
}
else
{
c=b;
d=a;
}
textbox3.text=c;//here the error 
textbox4.text=d;//also here


你能帮我解决这个问题吗?
在此先感谢

:)


can you help me to fix this
thanks in advance

:)

推荐答案

您正试图将浮点类型值分配给字符串文本框文本属性.
这样就得到了错误.

使用Convert.ToString()方法.
You are trying to assign a float type value to a string text box text attribute.
Thus you get the error.

Use the Convert.ToString() method.
textbox3.text=Convert.ToString(c);
textbox4.text=Convert.ToString(d);


执行此操作

do this

textbox3.text=c.ToString();


使用如下所示的string.formatToString float方法

Use string.format or ToString method of float as below

//N2 format for printing 2 decimal places. 
//or use other format as required
textbox3.text=string.Format("{0:N2}",c);
textbox4.text=string.Format("{0:N2}",d);
//or
textbox3.text=c.ToString("N2");
textbox3.text=d.ToString("N2");


这篇关于如何将浮动值插入文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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