Filter 数字过滤器-需要接受小数点吗?

Filter 数字过滤器-需要接受小数点吗?,filter,textbox,decimal,point,numeric,Filter,Textbox,Decimal,Point,Numeric,我从这里取了一个数字过滤器 但这不是我需要的,它不允许输入一个小数点 这个过滤器看起来像这样 DocumentFilter numericFilter = new DocumentFilter(){ @Override public void insertString(DocumentFilter.FilterBypass fb, int offset, String string, AttributeSet attr)

我从这里取了一个数字过滤器

但这不是我需要的,它不允许输入一个小数点

这个过滤器看起来像这样

DocumentFilter numericFilter = new DocumentFilter(){   

        @Override
        public void insertString(DocumentFilter.FilterBypass fb, int offset,
                String string, AttributeSet attr)
                throws BadLocationException {
            fb.insertString(offset, string.replaceAll("[^\\d]", ""), attr);
        }

        @Override
        public void replace(DocumentFilter.FilterBypass fb, int offset, int length,
                String text, AttributeSet attrs)
                throws BadLocationException {

            fb.replace(offset, length, text.replaceAll("[^\\d]", ""), attrs);
        }
    };
我怎样才能修改它,使它能够只包含一个小数点

谢谢


Phil

我在正则表达式中添加了一个“.”,但它允许使用多个小数?好吧,我在这里做了一些错误的事情,但没有回答我无法解决,我尝试了多个正则表达式示例,声称限制了小数点后两位,但都不起作用,事实上,大多数示例都阻止我输入任何数字。我完全被困在这里了。