List of usage examples for java.lang Float doubleValue
public double doubleValue()
From source file:Main.java
public static void main(String[] args) { Float floatObject = new Float("10.01"); double b = floatObject.doubleValue(); System.out.println("double:" + b); }
From source file:Main.java
public static void main(String[] args) { Float fObj = new Float("10.50"); byte b = fObj.byteValue(); System.out.println(b);/*from ww w . java 2 s . com*/ short s = fObj.shortValue(); System.out.println(s); int i = fObj.intValue(); System.out.println(i); float f = fObj.floatValue(); System.out.println(f); double d = fObj.doubleValue(); System.out.println(d); }
From source file:Main.java
/** * @param floats The list of {@link Float}s to be converted to {@link Double}s. * @return A list of {@link Double}s from a list of {@link Float}s. *//*from w ww .j a v a 2 s .c om*/ public static List<Double> doublesFromFloats(List<Float> floats) { List<Double> doubles = new ArrayList<>(); for (Float f : floats) { doubles.add(f.doubleValue()); } return doubles; }
From source file:Main.java
/** * //w w w . j av a 2 s. c om * @param values * @return */ public static Double[] toDoubleArray(List<Float> values) { Double[] doubles = new Double[values.size()]; int i = 0; for (Float float1 : values) { doubles[i++] = float1.doubleValue(); } return doubles; }
From source file:oscar.util.UtilMisc.java
public static String FloatToString(float value) { Float f = new Float(value); NumberFormat fmt = NumberFormat.getNumberInstance(); String s = fmt.format(f.doubleValue()); return s;/*from w w w .java 2 s . c om*/ }
From source file:Util.PacketGenerator.java
public static void GenerateGraph() { try {/*from w w w.ja v a2 s .co m*/ for (int j = 6; j <= 6; j++) { File real = new File("D:\\Mestrado\\SketchMatrix\\trunk\\Simulations\\Analise\\Scenario1\\Topology" + j + "\\Real.csv"); for (int k = 1; k <= 4; k++) { File simu = new File( "D:\\Mestrado\\SketchMatrix\\trunk\\Simulations\\Analise\\Scenario1\\Topology" + j + "\\SimulacaoInstancia" + k + ".csv"); FileInputStream simuFIS = new FileInputStream(simu); DataInputStream simuDIS = new DataInputStream(simuFIS); BufferedReader simuBR = new BufferedReader(new InputStreamReader(simuDIS)); FileInputStream realFIS = new FileInputStream(real); DataInputStream realDIS = new DataInputStream(realFIS); BufferedReader realBR = new BufferedReader(new InputStreamReader(realDIS)); String lineSimu = simuBR.readLine(); String lineReal = realBR.readLine(); XYSeries matrix = new XYSeries("Matriz", false, true); while (lineSimu != null && lineReal != null) { lineSimu = lineSimu.replaceAll(",", "."); String[] simuMatriz = lineSimu.split(";"); String[] realMatriz = lineReal.split(";"); for (int i = 0; i < simuMatriz.length; i++) { try { Integer valorReal = Integer.parseInt(realMatriz[i]); Float valorSimu = Float.parseFloat(simuMatriz[i]); matrix.add(valorReal.doubleValue() / 1000.0, valorSimu.doubleValue() / 1000.0); } catch (NumberFormatException ex) { } } lineSimu = simuBR.readLine(); lineReal = realBR.readLine(); } simuFIS.close(); simuDIS.close(); simuBR.close(); realFIS.close(); realDIS.close(); realBR.close(); double maxPlot = Double.max(matrix.getMaxX(), matrix.getMaxY()) * 1.1; XYSeries middle = new XYSeries("Referncia"); ; middle.add(0, 0); middle.add(maxPlot, maxPlot); XYSeries max = new XYSeries("Superior 20%"); max.add(0, 0); max.add(maxPlot, maxPlot * 1.2); XYSeries min = new XYSeries("Inferior 20%"); min.add(0, 0); min.add(maxPlot, maxPlot * 0.8); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(middle); dataset.addSeries(matrix); dataset.addSeries(max); dataset.addSeries(min); JFreeChart chart; if (k == 4) { chart = ChartFactory.createXYLineChart("Matriz de Trfego", "Real", "CMO-MT", dataset); } else { chart = ChartFactory.createXYLineChart("Matriz de Trfego", "CMO-MT", "Zhao", dataset); } chart.setBackgroundPaint(Color.WHITE); chart.getPlot().setBackgroundPaint(Color.WHITE); chart.getTitle().setFont(new Font("Times New Roman", Font.BOLD, 13)); chart.getLegend().setItemFont(new Font("Times New Roman", Font.TRUETYPE_FONT, 10)); chart.getXYPlot().getDomainAxis().setLabelFont(new Font("Times New Roman", Font.BOLD, 10)); chart.getXYPlot().getDomainAxis() .setTickLabelFont(new Font("Times New Roman", Font.TRUETYPE_FONT, 1)); chart.getXYPlot().getRangeAxis().setLabelFont(new Font("Times New Roman", Font.BOLD, 10)); chart.getXYPlot().getRangeAxis() .setTickLabelFont(new Font("Times New Roman", Font.TRUETYPE_FONT, 1)); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer(); renderer.setSeriesLinesVisible(1, false); renderer.setSeriesShapesVisible(1, true); renderer.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 0.1f }, 0.0f)); renderer.setSeriesShape(1, new Ellipse2D.Float(-1.5f, -1.5f, 3f, 3f)); renderer.setSeriesStroke(2, new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 3.0f }, 0.0f)); renderer.setSeriesStroke(3, new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 3.0f }, 0.0f)); renderer.setSeriesPaint(0, Color.BLACK); renderer.setSeriesPaint(1, Color.BLACK); renderer.setSeriesPaint(2, Color.BLACK); renderer.setSeriesPaint(3, Color.BLACK); int width = (int) (192 * 1.5f); /* Width of the image */ int height = (int) (144 * 1.5f); /* Height of the image */ File XYChart = new File( "D:\\Mestrado\\SketchMatrix\\trunk\\Simulations\\Analise\\Scenario1\\Topology" + j + "\\SimulacaoInstancia" + k + ".jpeg"); ChartUtilities.saveChartAsJPEG(XYChart, chart, width, height); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.github.jessemull.microflex.util.BigDecimalUtil.java
/** * Safely converts an object to a BigInteger. Loss of precision may occur. Throws * an arithmetic exception upon overflow. * @param Object object to parse// w ww .j a va2 s . c o m * @return parsed object * @throws ArithmeticException on overflow */ public static BigDecimal toBigDecimal(Object obj) { /* Switch on class and convert to BigDecimal */ String type = obj.getClass().getSimpleName(); BigDecimal parsed; switch (type) { case "Byte": Byte by = (Byte) obj; parsed = new BigDecimal(by.doubleValue()); break; case "Short": Short sh = (Short) obj; parsed = new BigDecimal(sh.doubleValue()); break; case "Integer": Integer in = (Integer) obj; parsed = new BigDecimal(in.doubleValue()); break; case "Long": Long lo = (Long) obj; parsed = new BigDecimal(lo.doubleValue()); break; case "Float": Float fl = (Float) obj; parsed = new BigDecimal(fl.doubleValue()); break; case "BigInteger": parsed = new BigDecimal(((BigInteger) obj)); break; case "BigDecimal": parsed = (BigDecimal) obj; break; case "Double": Double db = (Double) obj; parsed = new BigDecimal(db); break; default: throw new IllegalArgumentException( "Invalid type: " + type + "\nData values " + "must extend the abstract Number class."); } return parsed; }
From source file:com.github.jessemull.microflex.util.BigDecimalUtil.java
/** * Safely converts a number to a BigInteger. Loss of precision may occur. Throws * an arithmetic exception upon overflow. * @param Number object to parse/*from w w w . ja v a 2s . c o m*/ * @return parsed object * @throws ArithmeticException on overflow */ public static BigDecimal toBigDecimal(Number number) { /* Switch on class and convert to BigDecimal */ String type = number.getClass().getSimpleName(); BigDecimal parsed; switch (type) { case "Byte": Byte by = (Byte) number; parsed = new BigDecimal(by.doubleValue()); break; case "Short": Short sh = (Short) number; parsed = new BigDecimal(sh.doubleValue()); break; case "Integer": Integer in = (Integer) number; parsed = new BigDecimal(in.doubleValue()); break; case "Long": Long lo = (Long) number; parsed = new BigDecimal(lo.doubleValue()); break; case "Float": Float fl = (Float) number; parsed = new BigDecimal(fl.doubleValue()); break; case "BigInteger": parsed = new BigDecimal(((BigInteger) number)); break; case "BigDecimal": parsed = (BigDecimal) number; break; case "Double": Double db = (Double) number; parsed = new BigDecimal(db); break; default: throw new IllegalArgumentException( "Invalid type: " + type + "\nData values " + "must extend the abstract Number class."); } return parsed; }
From source file:pcgen.core.analysis.SkillRankControl.java
/** * Returns the total ranks of a skill rank + bonus ranks (racial, class, etc * bonuses). Note that the total ranks could be higher than the max ranks if * the ranks come from a familiar's master. * /* ww w .j av a 2 s.c om*/ * @param pc * @return rank + bonus ranks (racial, class, etc. bonuses) */ public static Float getTotalRank(PlayerCharacter pc, Skill sk) { if (pc == null) { Logging.errorPrint("Asked to get total rank for null character. Location was ", new Throwable()); return 0.0f; } Float rank = pc.getRank(sk); if (rank == null) { Logging.errorPrint("Rank of skill " + sk + " for " + pc + " was null. Location was ", new Throwable()); return 0.0f; } double baseRanks = rank.doubleValue(); double ranks = baseRanks + SkillRankControl.getSkillRankBonusTo(pc, sk); if (!Globals.checkRule(RuleConstants.SKILLMAX) && pc.hasClass()) { /* * Note: The class grabbed doesn't matter - it is only used for calculating cross-class skill rank cost. * All classes of a multi-class character are scanned to determine if the skill is a class skill. */ double maxRanks = pc.getMaxRank(sk, pc.getClassList().get(0)).doubleValue(); maxRanks = Math.max(maxRanks, baseRanks); ranks = Math.min(maxRanks, ranks); } return new Float(ranks); }
From source file:com.github.jessemull.microflex.util.DoubleUtil.java
/** * Safely converts an object to a double. Loss of precision may occur. Throws * an arithmetic exception upon overflow. * @param Object object to parse//from w w w .j ava 2s . c o m * @return parsed object * @throws ArithmeticException on overflow */ public static double toDouble(Object obj) { /* Switch on class and convert to double */ String type = obj.getClass().getSimpleName(); double parsed; switch (type) { case "Byte": Byte by = (Byte) obj; parsed = by.doubleValue(); break; case "Short": Short sh = (Short) obj; parsed = sh.doubleValue(); break; case "Integer": Integer in = (Integer) obj; parsed = in.doubleValue(); break; case "Long": Long lo = (Long) obj; parsed = lo.doubleValue(); break; case "Float": Float fl = (Float) obj; parsed = fl.doubleValue(); break; case "BigInteger": BigInteger bi = (BigInteger) obj; if (!OverFlowUtil.doubleOverflow(bi)) { throw new ArithmeticException("Overflow casting " + obj + " to a double."); } parsed = bi.doubleValue(); break; case "BigDecimal": BigDecimal bd = (BigDecimal) obj; if (!OverFlowUtil.doubleOverflow(bd)) { throw new ArithmeticException("Overflow casting " + obj + " to a double."); } parsed = bd.doubleValue(); break; case "Double": Double db = (Double) obj; parsed = db.doubleValue(); break; default: throw new IllegalArgumentException( "Invalid type: " + type + "\nData values " + "must extend the abstract Number class."); } return parsed; }