将浮点数显示到文本视图中。

8

我想在TextView中显示一个浮点数


你想将一个浮点数值设置到TextView上面是吗? - Venky
请详细阐述您的问题和情境。 - Sunil Pandey
是的,我想将一个浮点值设置到TextView中。 - mobileDeveloper
5个回答

19

试试这个:

 float myfloatvariable=(float) 2.33333;
 String mytext=Float.toString(myfloatvariable);
 TextView.setText(mytext);

如果您的变量类型为double,您也可以使用Double.toString(mydoubleVariable)。 - Kartik Domadiya

1

试试这个

  • myTextView.setText(Float.toString(floatVar));

  • myTextView.setText(String.valueOf(floatVar));

  • myTextView.setText(floatVar+"");


0
///// for float value ////
Float flt_value = 1.134f;
txt_total.setText(String.format("%.02f",flt_value));

///// for double value ////
double dbl_value = 1.134;
txt_total.setText(String.format("%.2f",dbl_value));

0

如果我理解你的意思正确,你想要类似于这样的东西

myText.setText = myFloat.toString();

0

这是我个人使用过的东西。

aTextView.setText(Float.toString(yourFloat));

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接