其实网上一搜一大把的文章,但是很多都是一个简单的问题写的很长,导致难以一目了然的找的我们的想要的。咱们来个简单粗暴的直接上代码
deduction.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence text, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable edt) {
String temp = edt.toString();
int posDot = temp.indexOf(".");
if (posDot <= 0) {
return;
}
if (temp.length() - posDot - 1 > n) {
edt.delete(posDot + (n+1), posDot + (n+2));
}
}
});
其中的n就是你要保留的小数点后数字的个数,很简单吧,拿去拿去。
文章推荐
1、CoordinatorLayout + AppBarLayout + NestedScrollView 组合使用实现地图背景,滑动悬停华丽效果。仿饿了么地图界面
https://blog.youkuaiyun.com/jason_rui/article/details/100222797
2、ViewPager 实现图片自动无限轮播、酷炫效果的实现(同时显示出多个item)、底部导航栏实现中间
https://blog.youkuaiyun.com/jason_rui/article/details/102501079