TableColumn<Product, Double> priceCol = new TableColumn<Product,Double>("Price");
priceCol.setCellValueFactory(new PropertyValueFactory<Product, Double>("price"));
How do I format the doubles in this column to have 2 decimal places(Because they are the column for price)?By default they only show 1 decimal place.
Use a cell factory that generates cells that use a currency formatter to format the text that is displayed. This means the price will be formatted as a currency in the current locale (i.e. using the local currency symbol and appropriate rules for number of decimal places, etc.).
Note this is in addition to the
cellValueFactory
you are already using. ThecellValueFactory
determines the value that is displayed in a cell; thecellFactory
determines the cell that defines how to display it.