Example usage for java.lang Byte floatValue

List of usage examples for java.lang Byte floatValue

Introduction

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

Prototype

public float floatValue() 

Source Link

Document

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

Usage

From source file:Main.java

public static void main(String[] args) {
    Byte byteObject = new Byte("10");
    float f = byteObject.floatValue();
    System.out.println("float" + f);

}

From source file:Main.java

public static void main(String[] args) {
    Byte bObj = new Byte("10");
    byte b = bObj.byteValue();
    System.out.println(b);//  w  w w  . j a v  a  2  s  .co 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: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;/*w w w.  j  a  va  2  s  .c  o  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.UDFToFloat.java

public Float evaluate(Byte i) {
    if (i == null) {
        return null;
    } else {/*from www. jav a2s.  co  m*/
        return Float.valueOf(i.floatValue());
    }
}

From source file:wwutil.jsoda.DataUtil.java

/** Caller should handle custom valueType first before calling this.
 * E.g. DynamoDB's Set<String> and Set<long> fields are encoded as Multi-Value AttributeValue.
 *///  w w w. jav a  2s. co m
@SuppressWarnings("unchecked")
static String encodeValueToAttrStr(Object value, Class valueType) {
    if (value == null)
        return null; // Caller needs to handle null correctly, e.g. skip storing AttributeValue.

    if (valueType == String.class)
        return value.toString();

    // NOTE: Don't change encoding and padding once data have been created.  Different encoding will mess up sorting.
    // Stringify basic type and encode them for sorting.
    if (valueType == Byte.class || valueType == byte.class) {
        Byte casted = (Byte) ConvertUtils.convert(value, Byte.class);
        return SimpleDBUtils.encodeZeroPadding(casted.intValue(), 3); // 0-Padded for sorting
    } else if (valueType == Short.class || valueType == short.class) {
        Short casted = (Short) ConvertUtils.convert(value, Short.class);
        return SimpleDBUtils.encodeZeroPadding(casted.intValue(), 5); // 0-Padded for sorting
    } else if (valueType == Integer.class || valueType == int.class) {
        Integer casted = (Integer) ConvertUtils.convert(value, Integer.class);
        return SimpleDBUtils.encodeZeroPadding(casted.intValue(), 10); // 0-Padded for sorting
    } else if (valueType == Long.class || valueType == long.class) {
        Long casted = (Long) ConvertUtils.convert(value, Long.class);
        return SimpleDBUtils.encodeZeroPadding(casted.longValue(), 19); // 0-Padded for sorting
    } else if (valueType == Float.class || valueType == float.class) {
        Float casted = (Float) ConvertUtils.convert(value, Float.class);
        return SimpleDBUtils.encodeZeroPadding(casted.floatValue(), 16); // 0-Padded for sorting
    } else if (valueType == Double.class || valueType == double.class) {
        // SimpleDBUtils has no padding for double.  Just convert it to String.
        return value.toString();
    } else if (valueType == Boolean.class || valueType == boolean.class) {
        return value.toString();
    } else if (valueType == Character.class || valueType == char.class) {
        return value.toString();
    } else if (valueType == Date.class) {
        return SimpleDBUtils.encodeDate((Date) value);
    } else if (valueType.isEnum()) {
        return ((Enum) value).name();
    }

    // JSONify the rest.
    return toJson(value);
}