Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
格式化Bigdecimal。JavaFX_Java_Javafx_Javafx 8_Bigdecimal - Fatal编程技术网

格式化Bigdecimal。JavaFX

格式化Bigdecimal。JavaFX,java,javafx,javafx-8,bigdecimal,Java,Javafx,Javafx 8,Bigdecimal,我想在我的JavaFx应用程序的TableColumn中打印BigDecimal。但我无法正确格式化它 我试过这个: DecimalFormat df = new DecimalFormat("#,###.00"); tc_ma_sell_amount.setCellValueFactory(cellData -> new SimpleStringProperty(df.format(cellData.getValue().getSellAmount()).toString())); 格

我想在我的
JavaFx
应用程序的TableColumn中打印
BigDecimal
。但我无法正确格式化它

我试过这个:

DecimalFormat df = new DecimalFormat("#,###.00");
tc_ma_sell_amount.setCellValueFactory(cellData -> new SimpleStringProperty(df.format(cellData.getValue().getSellAmount()).toString()));
格式正常,打印1005689.56。但这里的问题是,当我在应用程序中根据此列对表进行排序时,它引用这些值,就像它们是字符串一样,排序不正确

我做了以下修改:

tc_ma_sell_amount.setCellValueFactory(cellData -> new SimpleObjectProperty<BigDecimal>(cellData.getValue().getSellAmount()));
tc_ma_sell_amount.setCellValueFactory(cellData->new SimpleObject属性(cellData.getValue().getSellAmount());
在这里,格式不正确。(1005689.5600),但排序工作正常。为了获得正确的格式(“#,#,####.00”)和排序,我必须更改什么?

我自己做的

tc_ma_sell_amount.setCellFactory(param -> {
            return new TableCell<ConversionDeals, BigDecimal>(){
                @Override
                protected void updateItem(BigDecimal item, boolean empty) {
                    super.updateItem(item, empty);
                    if(empty || item == null){
                        setText("");
                    } else {
                        setText(df.format(item));
                    }
                }
            };
        });
tc\u ma\u销售金额。setCellFactory(参数->{
返回新的TableCell(){
@凌驾
受保护的void updateItem(BigDecimal项,布尔空){
super.updateItem(项,空);
if(空| |项==null){
setText(“”);
}否则{
setText(df.格式(项目));
}
}
};
});
我自己做的

tc_ma_sell_amount.setCellFactory(param -> {
            return new TableCell<ConversionDeals, BigDecimal>(){
                @Override
                protected void updateItem(BigDecimal item, boolean empty) {
                    super.updateItem(item, empty);
                    if(empty || item == null){
                        setText("");
                    } else {
                        setText(df.format(item));
                    }
                }
            };
        });
tc\u ma\u销售金额。setCellFactory(参数->{
返回新的TableCell(){
@凌驾
受保护的void updateItem(BigDecimal项,布尔空){
super.updateItem(项,空);
if(空| |项==null){
setText(“”);
}否则{
setText(df.格式(项目));
}
}
};
});

在BigDecimal源代码中。。。公共字符串toString(){String sc=stringCache;if(sc==null)stringCache=sc=layoutChars(true);在BigDecimal源中返回sc;}。。。公共字符串toString(){String sc=stringCache;if(sc==null)stringCache=sc=layoutChars(true);返回sc;}