Example usage for java.lang Number floatValue

List of usage examples for java.lang Number floatValue

Introduction

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

Prototype

public abstract float floatValue();

Source Link

Document

Returns the value of the specified number as a float .

Usage

From source file:org.nd4j.linalg.cpu.complex.ComplexFloat.java

@Override
public IComplexNumber rdivi(Number v, IComplexNumber result) {
    float d = result.realComponent().floatValue() * result.realComponent().floatValue()
            + result.imaginaryComponent().floatValue() * result.imaginaryComponent().floatValue();
    return result.set(v.floatValue() * result.realComponent().floatValue() / d,
            -v.floatValue() * result.imaginaryComponent().floatValue() / d);
}

From source file:nl.strohalm.cyclos.controls.reports.statistics.graphs.StatisticalDataProducer.java

/**
 * Cewolf needs this method for generation of tooltips when you hoover the mouse over a Pie graph section. If the settings are available, use
 * them, if not, then unformatted numbers will be shown. As tooltips are not essential, and as generation of them should never allow the rendering
 * of graphs to fail due to exceptions, all is inside a try catch block.
 * //  w w  w  . j av  a2s .  c om
 * @param dataset a <code>PieDataset</code>
 * @param key for identifying the section.
 * @param pieIndex in case of multiple Pie charts. Not used in cyclos.
 */
@Override
@SuppressWarnings("rawtypes")
public String generateToolTip(final PieDataset dataset, final Comparable key, final int pieIndex) {
    try {
        final Number number = dataset.getValue(key);
        try {
            final byte precision = (number instanceof StatisticalNumber)
                    ? ((StatisticalNumber) number).getPrecision()
                    : 0;
            if (settings != null) {
                final BigDecimal value = (new BigDecimal(1000).pow(scaleFactor))
                        .multiply(new BigDecimal(number.floatValue()));
                final int percentage = (int) Math
                        .round(value.divide(new BigDecimal(getTotalForPie())).doubleValue() * 100);
                final String result = settings.getNumberConverterForPrecision(precision).toString(value) + " (="
                        + percentage + "%)";
                return result;
            }
        } catch (final Exception e) {
            // if anything goes wrong, do nothing but continue with String.valueOf
        }
        final String result = String.valueOf(number.doubleValue());
        final int percentage = (int) Math.round(100 * (number.doubleValue() / getTotalForPie()));
        return result + " (=" + percentage + "%)";
    } catch (final Exception e) {
        // if all failed, just return no tooltips
        return "";
    }
}

From source file:nl.strohalm.cyclos.controls.reports.statistics.graphs.StatisticalDataProducer.java

/**
 * Cewolf needs this method for generation of tooltips when you hoover the mouse over a graph bar or point If the settings are available, use
 * them, if not, then unformatted numbers will be shown As tooltips are not essential, and as generation of them should never allow the rendering
 * of graphs to fail due to exceptions, all is inside a try catch block.
 *//*from  ww w  .j av  a2s.  co m*/
@Override
public String generateToolTip(final CategoryDataset lDataset, final int series, final int lCategories) {
    try {
        final Number number = lDataset.getValue(series, lCategories);
        try {
            final byte precision = (number instanceof StatisticalNumber)
                    ? ((StatisticalNumber) number).getPrecision()
                    : 0;
            if (settings != null) {
                final BigDecimal value = (new BigDecimal(1000).pow(scaleFactor))
                        .multiply(new BigDecimal(number.floatValue()));
                final String result = settings.getNumberConverterForPrecision(precision).toString(value);
                return result;
            }
        } catch (final Exception e) {
            // if anything goes wrong, do nothing but continue with String.valueOf
        }
        return String.valueOf(number.doubleValue());
    } catch (final Exception e) {
        // if all failed, just return no tooltips
        return "";
    }
}

From source file:org.jasper.collectionspace.smk.datasource.JsonCSDataSource.java

protected Object convertNumber(Number number, Class<?> valueClass) throws JRException {
    Number value = null;/*from w w  w. j  a  v a2 s. c o  m*/
    if (valueClass.equals(Byte.class)) {
        value = new Byte(number.byteValue());
    } else if (valueClass.equals(Short.class)) {
        value = new Short(number.shortValue());
    } else if (valueClass.equals(Integer.class)) {
        value = Integer.valueOf(number.intValue());
    } else if (valueClass.equals(Long.class)) {
        value = new Long(number.longValue());
    } else if (valueClass.equals(Float.class)) {
        value = new Float(number.floatValue());
    } else if (valueClass.equals(Double.class)) {
        value = new Double(number.doubleValue());
    } else if (valueClass.equals(BigInteger.class)) {
        value = BigInteger.valueOf(number.longValue());
    } else if (valueClass.equals(BigDecimal.class)) {
        value = new BigDecimal(Double.toString(number.doubleValue()));
    } else {
        throw new JRException("Unknown number class " + valueClass.getName());
    }
    return value;
}

From source file:org.apache.calcite.runtime.SqlFunctions.java

public static float toFloat(Number number) {
    return number.floatValue();
}

From source file:org.cloudgraph.hbase.results.ResultsAggregator.java

private void initAggregate(FunctionPath funcPath, PlasmaDataGraph graph) {
    DataType scalarType = funcPath.getFunc().getName().getScalarDatatype(funcPath.getDataType());
    PlasmaDataObject newEndpoint = null;
    if (funcPath.getPath().size() == 0) {
        newEndpoint = (PlasmaDataObject) graph.getRootObject();
    } else {//from  ww w.  java 2s  .c  o  m
        newEndpoint = (PlasmaDataObject) graph.getRootObject().getDataObject(funcPath.getPath().toString());
    }

    if (funcPath.getFunc().getName().ordinal() == FunctionName.COUNT.ordinal()) {
        Long newCount = new Long(1);
        newEndpoint.set(funcPath.getFunc().getName(), funcPath.getProperty(), newCount);
        // FIXME: original scalar value is irrelevant for aggregates
        // but need for comparison
        // newEndpoint.unset(funcPath.getProperty());
    } else {
        if (newEndpoint.isSet(funcPath.getProperty())) {
            Object newValue = newEndpoint.get(funcPath.getProperty());
            Number newScalarValue = (Number) DataConverter.INSTANCE.convert(scalarType,
                    funcPath.getProperty().getType(), newValue);
            // newEndpoint.unset(funcPath.getProperty());
            switch (funcPath.getFunc().getName()) {
            case AVG:
                switch (scalarType) {
                case Double:
                    Double doubleAvg = newScalarValue.doubleValue();
                    newEndpoint.set(funcPath.getFunc().getName(), funcPath.getProperty(), doubleAvg);
                    break;
                case Float:
                    Float floatAvg = newScalarValue.floatValue();
                    newEndpoint.set(funcPath.getFunc().getName(), funcPath.getProperty(), floatAvg);
                    break;
                default:
                    throw new IllegalArgumentException("illsgal datatype (" + scalarType
                            + ") conversion for function, " + funcPath.getFunc().getName());
                }
                break;
            case MAX:
                newEndpoint.set(funcPath.getFunc().getName(), funcPath.getProperty(), newScalarValue);
                break;
            case MIN:
                newEndpoint.set(funcPath.getFunc().getName(), funcPath.getProperty(), newScalarValue);
                break;
            case SUM:
                switch (scalarType) {
                case Double:
                    Double sum = newScalarValue.doubleValue();
                    newEndpoint.set(funcPath.getFunc().getName(), funcPath.getProperty(), sum);
                    break;
                case Float:
                    Float floatSum = newScalarValue.floatValue();
                    newEndpoint.set(funcPath.getFunc().getName(), funcPath.getProperty(), floatSum);
                    break;
                case Long:
                    Long longSum = newScalarValue.longValue();
                    newEndpoint.set(funcPath.getFunc().getName(), funcPath.getProperty(), longSum);
                    break;
                default:
                    throw new IllegalArgumentException("illsgal datatype (" + scalarType
                            + ") conversion for function, " + funcPath.getFunc().getName());
                }
                break;
            case COUNT:
                break; // handled above
            default:
                throw new GraphServiceException(
                        "unimplemented aggregate function, " + funcPath.getFunc().getName());
            }
        } else if (!funcPath.getProperty().isNullable())
            log.warn("expected value for non-nullable property, " + funcPath.getProperty());
    }
}

From source file:com.jkoolcloud.tnt4j.streams.utils.Utils.java

/**
 * Casts provided number value to desired number type.
 *
 * @param num/* w  ww.j  a  v a 2 s . com*/
 *            number value to cast
 * @param clazz
 *            number class to cast number to
 * @param <T>
 *            desired number type
 * @return number value cast to desired numeric type
 */
@SuppressWarnings("unchecked")
public static <T extends Number> T castNumber(Number num, Class<T> clazz) {
    Number cNum = 0;

    if (clazz.isAssignableFrom(Long.class)) {
        cNum = num.longValue();
    } else if (clazz.isAssignableFrom(Integer.class)) {
        cNum = num.intValue();
    } else if (clazz.isAssignableFrom(Byte.class)) {
        cNum = num.byteValue();
    } else if (clazz.isAssignableFrom(Float.class)) {
        cNum = num.floatValue();
    } else if (clazz.isAssignableFrom(Double.class)) {
        cNum = num.doubleValue();
    } else if (clazz.isAssignableFrom(Short.class)) {
        cNum = num.shortValue();
    }

    return (T) cNum;
}

From source file:com.itelis.worker.dev.template.service.JRXmlDataSource.java

protected Object convertNumber(Number number, Class valueClass) throws JRException {
    Number value = null;//from  w  ww .j  a v a 2 s . c  o  m
    if (valueClass.equals(Byte.class)) {
        value = new Byte(number.byteValue());
    } else if (valueClass.equals(Short.class)) {
        value = new Short(number.shortValue());
    } else if (valueClass.equals(Integer.class)) {
        value = new Integer(number.intValue());
    } else if (valueClass.equals(Long.class)) {
        value = new Long(number.longValue());
    } else if (valueClass.equals(Float.class)) {
        value = new Float(number.floatValue());
    } else if (valueClass.equals(Double.class)) {
        value = new Double(number.doubleValue());
    } else if (valueClass.equals(BigInteger.class)) {
        value = BigInteger.valueOf(number.longValue());
    } else if (valueClass.equals(BigDecimal.class)) {
        value = new BigDecimal(Double.toString(number.doubleValue()));
    } else {
        throw new JRException("Unknown number class " + valueClass.getName());
    }
    return value;
}

From source file:org.apache.fontbox.cff.Type1CharString.java

/**
 * Standard Encoding Accented Character//ww w.  j a  v  a2  s.  c  o  m
 *
 * Makes an accented character from two other characters.
 * @param asb 
 */
private void seac(Number asb, Number adx, Number ady, Number bchar, Number achar) {
    // base character
    String baseName = StandardEncoding.INSTANCE.getName(bchar.intValue());
    if (baseName != null) {
        try {
            Type1CharString base = font.getType1CharString(baseName);
            path.append(base.getPath().getPathIterator(null), false);
        } catch (IOException e) {
            LOG.warn("invalid seac character in glyph " + glyphName + " of font " + fontName);
        }
    }
    // accent character
    String accentName = StandardEncoding.INSTANCE.getName(achar.intValue());
    if (accentName != null) {
        try {
            Type1CharString accent = font.getType1CharString(accentName);
            AffineTransform at = AffineTransform.getTranslateInstance(leftSideBearing.getX() + adx.floatValue(),
                    leftSideBearing.getY() + ady.floatValue());
            path.append(accent.getPath().getPathIterator(at), false);
        } catch (IOException e) {
            LOG.warn("invalid seac character in glyph " + glyphName + " of font " + fontName);
        }
    }
}

From source file:org.op4j.functions.FnFloat.java

private static Float fromNumber(final Number number) {
    if (number == null) {
        return null;
    }//from   ww  w. j a  v a 2s  .  c o  m
    return Float.valueOf(number.floatValue());
}