Example usage for java.lang Byte doubleValue

List of usage examples for java.lang Byte doubleValue

Introduction

In this page you can find the example usage for java.lang Byte doubleValue.

Prototype

public double doubleValue() 

Source Link

Document

Returns the value of this Byte as a double after a widening primitive conversion.

Usage

From source file:Main.java

public static void main(String[] args) {
    Byte byteObject = new Byte("10");

    double d = byteObject.doubleValue();
    System.out.println("double:" + d);

}

From source file:Main.java

public static void main(String[] args) {
    Byte bObj = new Byte("10");
    byte b = bObj.byteValue();
    System.out.println(b);/*from   w  w  w. j av  a  2  s  .  c  o  m*/
    short s = bObj.shortValue();
    System.out.println(s);
    int i = bObj.intValue();
    System.out.println(i);
    float f = bObj.floatValue();
    System.out.println(f);
    double d = bObj.doubleValue();
    System.out.println(d);
    long l = bObj.longValue();
    System.out.println(l);

}

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//from  w  w w  .  ja  v a  2s .  co 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 . jav a  2 s. 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: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  av a 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;
}

From source file:com.github.jessemull.microflex.util.DoubleUtil.java

/**
 * Safely converts a number to a double. Loss of precision may occur. Throws
 * an arithmetic exception upon overflow.
 * @param    Number    number to parse/*from   www.j  ava 2 s.  c  om*/
 * @return             parsed number
 * @throws   ArithmeticException    on overflow
 */
public static double toDouble(Number number) {

    /* Switch on class and convert to double */

    String type = number.getClass().getSimpleName();
    double parsed;

    switch (type) {

    case "Byte":
        Byte by = (Byte) number;
        parsed = by.doubleValue();
        break;

    case "Short":
        Short sh = (Short) number;
        parsed = sh.doubleValue();
        break;

    case "Integer":
        Integer in = (Integer) number;
        parsed = in.doubleValue();
        break;

    case "Long":
        Long lo = (Long) number;
        parsed = lo.doubleValue();
        break;

    case "Float":
        Float fl = (Float) number;
        parsed = fl.doubleValue();
        break;

    case "BigInteger":
        BigInteger bi = (BigInteger) number;
        if (!OverFlowUtil.doubleOverflow(bi)) {
            throw new ArithmeticException("Overflow casting " + number + " to a double.");
        }
        parsed = bi.doubleValue();
        break;

    case "BigDecimal":
        BigDecimal bd = (BigDecimal) number;
        if (!OverFlowUtil.doubleOverflow(bd)) {
            throw new ArithmeticException("Overflow casting " + number + " to a double.");
        }
        parsed = bd.doubleValue();
        break;

    case "Double":
        Double db = (Double) number;
        parsed = db.doubleValue();
        break;

    default:
        throw new IllegalArgumentException(
                "Invalid type: " + type + "\nData values " + "must extend the abstract Number class.");

    }

    return parsed;
}

From source file:org.hellojavaer.poi.excel.utils.ExcelUtils.java

@SuppressWarnings("unused")
private static void writeCell(Cell cell, Object val, boolean userTemplate,
        ExcelWriteFieldMappingAttribute attribute, Object bean) {
    if (attribute != null && attribute.getLinkField() != null) {
        String addressFieldName = attribute.getLinkField();
        String address = null;/*from   w  ww  . j  a va 2 s.  co  m*/
        if (bean != null) {
            address = (String) getFieldValue(bean, addressFieldName, true);
        }
        Workbook wb = cell.getRow().getSheet().getWorkbook();

        Hyperlink link = wb.getCreationHelper().createHyperlink(attribute.getLinkType());
        link.setAddress(address);
        cell.setHyperlink(link);
        // Its style can't inherit from cell.
        CellStyle style = wb.createCellStyle();
        Font hlinkFont = wb.createFont();
        hlinkFont.setUnderline(Font.U_SINGLE);
        hlinkFont.setColor(IndexedColors.BLUE.getIndex());
        style.setFont(hlinkFont);
        if (cell.getCellStyle() != null) {
            style.setFillBackgroundColor(cell.getCellStyle().getFillBackgroundColor());
        }
        cell.setCellStyle(style);
    }
    if (val == null) {
        cell.setCellValue((String) null);
        return;
    }
    Class<?> clazz = val.getClass();
    if (val instanceof Byte) {// Double
        Byte temp = (Byte) val;
        cell.setCellValue((double) temp.byteValue());
    } else if (val instanceof Short) {
        Short temp = (Short) val;
        cell.setCellValue((double) temp.shortValue());
    } else if (val instanceof Integer) {
        Integer temp = (Integer) val;
        cell.setCellValue((double) temp.intValue());
    } else if (val instanceof Long) {
        Long temp = (Long) val;
        cell.setCellValue((double) temp.longValue());
    } else if (val instanceof Float) {
        Float temp = (Float) val;
        cell.setCellValue((double) temp.floatValue());
    } else if (val instanceof Double) {
        Double temp = (Double) val;
        cell.setCellValue((double) temp.doubleValue());
    } else if (val instanceof Date) {// Date
        Date dateVal = (Date) val;
        long time = dateVal.getTime();
        // read is based on 1899/12/31 but DateUtil.getExcelDate is base on
        // 1900/01/01
        if (time >= TIME_1899_12_31_00_00_00_000 && time < TIME_1900_01_01_00_00_00_000) {
            Date incOneDay = new Date(time + 24 * 60 * 60 * 1000);
            double d = DateUtil.getExcelDate(incOneDay);
            cell.setCellValue(d - 1);
        } else {
            cell.setCellValue(dateVal);
        }

        if (!userTemplate) {
            Workbook wb = cell.getRow().getSheet().getWorkbook();
            CellStyle cellStyle = cell.getCellStyle();
            if (cellStyle == null) {
                cellStyle = wb.createCellStyle();
            }
            DataFormat dataFormat = wb.getCreationHelper().createDataFormat();
            // @see #BuiltinFormats
            // 0xe, "m/d/yy"
            // 0x14 "h:mm"
            // 0x16 "m/d/yy h:mm"
            // {@linke https://en.wikipedia.org/wiki/Year_10,000_problem}
            /** [1899/12/31 00:00:00:000~1900/01/01 00:00:000) */
            if (time >= TIME_1899_12_31_00_00_00_000 && time < TIME_1900_01_02_00_00_00_000) {
                cellStyle.setDataFormat(dataFormat.getFormat("h:mm"));
                // cellStyle.setDataFormat(dataFormat.getFormat("m/d/yy h:mm"));
            } else {
                // if ( time % (24 * 60 * 60 * 1000) == 0) {//for time
                // zone,we can't use this way.
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(dateVal);
                int hour = calendar.get(Calendar.HOUR_OF_DAY);
                int minute = calendar.get(Calendar.MINUTE);
                int second = calendar.get(Calendar.SECOND);
                int millisecond = calendar.get(Calendar.MILLISECOND);
                if (millisecond == 0 && second == 0 && minute == 0 && hour == 0) {
                    cellStyle.setDataFormat(dataFormat.getFormat("m/d/yy"));
                } else {
                    cellStyle.setDataFormat(dataFormat.getFormat("m/d/yy h:mm"));
                }
            }
            cell.setCellStyle(cellStyle);
        }
    } else if (val instanceof Boolean) {// Boolean
        cell.setCellValue(((Boolean) val).booleanValue());
    } else {// String
        cell.setCellValue((String) val.toString());
    }
}

From source file:org.apache.hadoop.hive.ql.udf.UDFToDouble.java

public Double evaluate(Byte i) {
    if (i == null) {
        return null;
    } else {//from  w  w  w  . ja v a 2  s .com
        return Double.valueOf(i.doubleValue());
    }
}