Account for exponential notation in CSV export

This commit is contained in:
SiboVG 2023-03-14 23:32:36 +01:00
parent d02b8fc431
commit 47837287e5
2 changed files with 8 additions and 5 deletions

View File

@ -87,10 +87,11 @@ public class SimulationTableCSVExport {
* Generate the CSV data from the simulation table * Generate the CSV data from the simulation table
* @param fieldSep The field separator to use in the CSV file. * @param fieldSep The field separator to use in the CSV file.
* @param precision The number of decimal places to use in the CSV file. * @param precision The number of decimal places to use in the CSV file.
* @param isExponentialNotation If true, use exponential notation for numbers.
* @param onlySelected If true, only export the selected rows in the table. * @param onlySelected If true, only export the selected rows in the table.
* @return The CSV data as one string block. * @return The CSV data as one string block.
*/ */
public String generateCSVDate(String fieldSep, int precision, boolean onlySelected) { public String generateCSVDate(String fieldSep, int precision, boolean isExponentialNotation, boolean onlySelected) {
int modelColumnCount = simulationTableModel.getColumnCount(); int modelColumnCount = simulationTableModel.getColumnCount();
int modelRowCount = simulationTableModel.getRowCount(); int modelRowCount = simulationTableModel.getRowCount();
populateColumnNameToUnitsHashTable(); populateColumnNameToUnitsHashTable();
@ -154,7 +155,7 @@ public class SimulationTableCSVExport {
final String valueString; final String valueString;
if (o instanceof Value) { if (o instanceof Value) {
double value = ((Value) o).getUnitValue(); double value = ((Value) o).getUnitValue();
valueString = TextUtil.doubleToString(value, precision); valueString = TextUtil.doubleToString(value, precision, isExponentialNotation);
} else { } else {
valueString = o.toString(); valueString = o.toString();
} }
@ -188,15 +189,16 @@ public class SimulationTableCSVExport {
* @param file the file to save the results to * @param file the file to save the results to
* @param fieldSep the CSV separator to use * @param fieldSep the CSV separator to use
* @param precision the decimal precision to use in the CSV file * @param precision the decimal precision to use in the CSV file
* @param isExponentialNotation if true, use exponential notation for numbers
* @param onlySelected if true, only export the selected rows in the table * @param onlySelected if true, only export the selected rows in the table
*/ */
public void export(File file, String fieldSep, int precision, boolean onlySelected) { public void export(File file, String fieldSep, int precision, boolean isExponentialNotation, boolean onlySelected) {
if (file == null) { if (file == null) {
log.warn("No file selected for export"); log.warn("No file selected for export");
return; return;
} }
String CSVData = generateCSVDate(fieldSep, precision, onlySelected); String CSVData = generateCSVDate(fieldSep, precision, isExponentialNotation, onlySelected);
this.dumpDataToFile(CSVData, file); this.dumpDataToFile(CSVData, file);
log.info("Simulation table data exported to " + file.getAbsolutePath()); log.info("Simulation table data exported to " + file.getAbsolutePath());
} }

View File

@ -420,6 +420,7 @@ public class SimulationPanel extends JPanel {
String separator = ((CsvOptionPanel) fch.getAccessory()).getFieldSeparator(); String separator = ((CsvOptionPanel) fch.getAccessory()).getFieldSeparator();
int precision = ((CsvOptionPanel) fch.getAccessory()).getDecimalPlaces(); int precision = ((CsvOptionPanel) fch.getAccessory()).getDecimalPlaces();
boolean isExponentialNotation = ((CsvOptionPanel) fch.getAccessory()).isExponentialNotation();
((CsvOptionPanel) fch.getAccessory()).storePreferences(); ((CsvOptionPanel) fch.getAccessory()).storePreferences();
// Handle some special separator options from CsvOptionPanel // Handle some special separator options from CsvOptionPanel
@ -430,7 +431,7 @@ public class SimulationPanel extends JPanel {
} }
SimulationTableCSVExport exporter = new SimulationTableCSVExport(document, simulationTable, simulationTableModel); SimulationTableCSVExport exporter = new SimulationTableCSVExport(document, simulationTable, simulationTableModel);
exporter.export(CSVFile, separator, precision, onlySelected); exporter.export(CSVFile, separator, precision, isExponentialNotation, onlySelected);
} }
/** /**