List of usage examples for java.lang Double parseDouble
public static double parseDouble(String s) throws NumberFormatException
From source file:com.zlfun.framework.table.ItemComparator.java
@Override public int compare(T o1, T o2) { Map<String, String> o1m = TableUtils.genItemFieldMap(o1); Map<String, String> o2m = TableUtils.genItemFieldMap(o2); String var1 = o1m.get(name); String var2 = o2m.get(name); if (isNumeric(var1) && isNumeric(var2)) { if (asc) { return Double.compare(Double.parseDouble(var1), Double.parseDouble(var2)); } else {/* w w w . j a v a2 s . c o m*/ return Double.compare(Double.parseDouble(var2), Double.parseDouble(var1)); } } else { if (asc) { return var1.compareTo(var2); } else { return var2.compareTo(var1); } } }
From source file:game.plugins.valuetemplates.VectorTemplate.java
@Override public RealVector loadValue(List<String> description) { RealVector ret = new ArrayRealVector(dimension); int i = 0;// www . j av a 2 s .co m try { for (String s : description) ret.setEntry(i++, Double.parseDouble(s)); } catch (Exception e) { System.out.println("oh"); } return ret; }
From source file:org.openimaj.demos.sandbox.flickr.geo.PlotFlickrGeo.java
public static void main(String[] args) throws IOException { final File inputcsv = new File("/Volumes/SSD/training_latlng"); final List<double[]> data = new ArrayList<double[]>(10000000); // read in images final BufferedReader br = new BufferedReader(new FileReader(inputcsv)); String line;/* w ww .j av a2 s .c om*/ int i = 0; br.readLine(); while ((line = br.readLine()) != null) { final String[] parts = line.split(" "); final double longitude = Double.parseDouble(parts[2]); final double latitude = Double.parseDouble(parts[1]); data.add(new double[] { longitude, latitude }); if (longitude >= -0.1 && longitude < 0 && latitude > 50 && latitude < 54) System.out.println(parts[0] + " " + latitude + " " + longitude); // if (i++ % 10000 == 0) // System.out.println(i); } br.close(); System.out.println("Done reading"); final float[][] dataArr = new float[2][data.size()]; for (i = 0; i < data.size(); i++) { dataArr[0][i] = (float) data.get(i)[0]; dataArr[1][i] = (float) data.get(i)[1]; } final NumberAxis domainAxis = new NumberAxis("X"); domainAxis.setRange(-180, 180); final NumberAxis rangeAxis = new NumberAxis("Y"); rangeAxis.setRange(-90, 90); final FastScatterPlot plot = new FastScatterPlot(dataArr, domainAxis, rangeAxis); final JFreeChart chart = new JFreeChart("Fast Scatter Plot", plot); chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); final ApplicationFrame frame = new ApplicationFrame("Title"); frame.setContentPane(chartPanel); frame.pack(); frame.setVisible(true); }
From source file:com.swcguild.springmvcwebapp.controller.UnitConverterController.java
@RequestMapping(value = "/unitConverter", method = RequestMethod.POST) public String convertUnits(HttpServletRequest request, Model model) { try {// w w w . j a va2 s.c o m originalValue = Double.parseDouble(request.getParameter("originalValue")); conversionType = request.getParameter("conversionType"); convertFrom = request.getParameter("convertFrom"); convertTo = request.getParameter("convertTo"); if (conversionType.equalsIgnoreCase("Temperature")) { result = convertTemp(originalValue); if (convertFrom.equals("1")) { convertFrom = "Fahrenheit"; } else if (convertFrom.equals("2")) { convertFrom = "Celsius"; } else { convertFrom = "Kelvin"; } if (convertTo.equals("1")) { convertTo = "Fahrenheit"; } else if (convertTo.equals("2")) { convertTo = "Celsius"; } else { convertTo = "Kelvin"; } } if (conversionType.equalsIgnoreCase("Currency")) { result = convertCurrency(originalValue); if (convertFrom.equals("1")) { convertFrom = "Dollars"; } else { convertFrom = "Euro"; } if (convertTo.equals("1")) { convertTo = "Dollars"; } else { convertTo = "Euro"; } } if (conversionType.equalsIgnoreCase("Volume")) { result = convertVolume(originalValue); if (convertFrom.equals("1")) { convertFrom = "Gallon"; } else { convertFrom = "Liter"; } if (convertTo.equals("1")) { convertTo = "Gallon"; } else { convertTo = "Liter"; } } if (conversionType.equalsIgnoreCase("Mass")) { result = convertMass(originalValue); if (convertFrom.equals("1")) { convertFrom = "Pound"; } else { convertFrom = "Kilogram"; } if (convertTo.equals("1")) { convertTo = "Pound"; } else { convertTo = "Kilogram"; } } DecimalFormat df = new DecimalFormat("0.00"); model.addAttribute("result", df.format(result)); model.addAttribute("originalValue", df.format(originalValue)); model.addAttribute("conversionType", conversionType); model.addAttribute("convertFrom", convertFrom); model.addAttribute("convertTo", convertTo); // model.addAttribute("originalAmount", df.format(originalAmount)); // model.addAttribute("tipAmount", df.format(tipAmount)); // model.addAttribute("tipPercentage", df.format(tipPercentage)); // model.addAttribute("finalAmount", df.format(finalAmount)); } catch (NumberFormatException e) { } return "unitConverterResponse"; }
From source file:com.glaf.core.config.CustomProperties.java
public static double getDouble(String key) { if (hasObject(key)) { String value = properties.getProperty(key); return Double.parseDouble(value); }/* w w w .j a v a 2 s . c o m*/ return 0; }
From source file:gov.nih.nci.caarray.application.util.Utils.java
/** * @param value the value to test.//from ww w. j a va 2s. c o m * @return true is the value can be parsed as an Double. */ public static boolean isDouble(String value) { try { Double.parseDouble(value); return true; } catch (NumberFormatException e) { return false; } }
From source file:de.qaware.chronix.solr.type.metric.functions.transformation.Scale.java
/** * Scales the time series by the given factor * * @param value the value factor */ public Scale(String[] args) { this.value = Double.parseDouble(args[0]); }
From source file:eu.cassandra.sim.utilities.Utils.java
public static double getDouble(Object o) { if (o == null) { return 0.0; } else {// w w w . ja v a2 s . c o m return Double.parseDouble(o.toString()); } }
From source file:net.poemerchant.entity.Buyout.java
public Buyout(String raw) { this.raw = raw; String[] split = raw.split(" "); this.buyoutMode = BuyoutMode.parse(split[0]); String amountRaw = split[1];//from w w w . j a v a2 s .c om // for typos e.g. ~b/o 0,5 exa amountRaw = StringUtils.replaceChars(amountRaw, ',', '.'); this.amount = Double.parseDouble(amountRaw); this.currency = Currency.parse(split[2]); }
From source file:ip.ui.LearningParamsInputPanel.java
public double getLearningRate() throws EmptyInputFieldException { String learningRateParam = learningRateInput.getText(); if (StringUtils.isEmpty(learningRateParam)) { throw new EmptyInputFieldException(learningRateLabel.getText()); }/*from w w w .j a v a 2 s. com*/ return Double.parseDouble(learningRateParam); }