android中TextView能直接显示整数或浮点数吗?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了android中TextView能直接显示整数或浮点数吗?相关的知识,希望对你有一定的参考价值。

参考技术A

android中TextView能直接显示整数或浮点数。

在android中将字符型转化为浮点型可以通过以下代码实现:

String   s; 

... 

try 

 

float   f   =   Float.parseFloat(s); 

 

catch(NumberFormatException   e) 

 

//... 

参考技术B 不行
textView.setText(CharSequence cs)
textView.setText(int resid)
textView.setText(char[] c,...)
textView的setText方法只有这么几种,char[]和resid都不行,
String implements CharSequence
可以这样:
double d=1.20;
CharSequence cs=String.valueOf(d);
textView.setText(cs);
但还是转字符串了

以上是关于android中TextView能直接显示整数或浮点数吗?的主要内容,如果未能解决你的问题,请参考以下文章