Example usage for java.math BigDecimal floatValue

List of usage examples for java.math BigDecimal floatValue

Introduction

In this page you can find the example usage for java.math BigDecimal floatValue.

Prototype

@Override
public float floatValue() 

Source Link

Document

Converts this BigDecimal to a float .

Usage

From source file:com.netsteadfast.greenstep.bsc.command.ScoreCalculationCommand.java

private float getWeightPercentage(BigDecimal weight) {
    if (weight == null) {
        return 0.0f;
    }//from  w  w w  .  j  ava 2  s .  c  om
    if (weight.floatValue() == 0.0f) {
        return 0.0f;
    }
    return weight.floatValue() / 100.0f;
}

From source file:org.hoteia.qalingo.core.solr.service.impl.ProductMarketingSolrServiceImpl.java

public void addOrUpdateProductMarketing(final ProductMarketing productMarketing,
        final List<CatalogCategoryVirtual> catalogCategories, final MarketArea marketArea,
        final Retailer retailer) throws SolrServerException, IOException {
    if (productMarketing.getId() == null) {
        throw new IllegalArgumentException("Id  cannot be blank or null.");
    }//  ww  w  .  ja v  a2s .  c o  m
    if (logger.isDebugEnabled()) {
        logger.debug("Indexing productMarketing " + productMarketing.getId());
        logger.debug("Indexing productMarketing " + productMarketing.getBusinessName());
        logger.debug("Indexing productMarketing " + productMarketing.getDescription());
        logger.debug("Indexing productMarketing " + productMarketing.getCode());
    }

    ProductMarketingSolr productSolr = new ProductMarketingSolr();
    productSolr.setId(productMarketing.getId());
    productSolr.setBusinessname(productMarketing.getBusinessName());
    productSolr.setDescription(productMarketing.getDescription());
    productSolr.setCode(productMarketing.getCode());
    if (productMarketing.getDefaultCatalogCategory() != null) {
        productSolr.setDefaultCategoryCode(productMarketing.getDefaultCatalogCategory().getCode());
    }
    ProductSkuPrice productSkuPrice = productMarketing.getDefaultProductSku().getPrice(marketArea.getId(),
            retailer.getId());
    if (productSkuPrice != null) {
        BigDecimal salePrice = productSkuPrice.getSalePrice();
        productSolr.setPrice(salePrice.floatValue());
    }

    if (catalogCategories != null) {
        for (CatalogCategoryVirtual catalogCategoryVirtual : catalogCategories) {
            productSolr.addCatalogCategories(catalogCategoryVirtual.getCode());
        }
    }

    productMarketingSolrServer.addBean(productSolr);
    productMarketingSolrServer.commit();
}

From source file:com.skratchdot.electribe.model.esx.impl.SampleTuneImpl.java

/**
 * <!-- begin-user-doc -->// w  ww .  ja  v  a2  s.  c  om
 * Calculates the SampleTune value from the given sampleRate (using a
 * baseSamplingRate of 44100)
 * <p>Formula Used:</p>
 * <table>
 * <tr><td></td><td align="center">log(sampleRate/44100)</td><td></td></tr>
 * <tr><td>12 *</td><td align="center">----------------------</td><td>= SampleTune</td></tr>
 * <tr><td></td><td align="center">log(2)</td><td></td></tr>
 * </table>
 * <!-- end-user-doc -->
 * @generated NOT
 */
public float calculateSampleTuneFromSampleRate(int sampleRate) {
    float x = ((float) sampleRate) / 44100;
    float y = (float) Math.log(x);
    float z = (float) (y / Math.log(2));
    BigDecimal bd = new BigDecimal(12 * z).setScale(2, RoundingMode.HALF_EVEN);
    return bd.floatValue();
}

From source file:de.brendamour.jpasskit.server.PKRestletServerResourceFactory.java

public PKPassResource getPKPassResource() {
    return new PKPassResource("passes/coupons.raw") {

        @Override//from  www .ja v a  2 s.  co  m
        protected GetPKPassResponse handleGetLatestVersionOfPass(final String passTypeIdentifier,
                final String serialNumber, final String authString, final Date modifiedSince)
                throws PKAuthTokenNotValidException, PKPassNotModifiedException {
            PKPass pass = new PKPass();
            try {
                pass = jsonObjectMapper.readValue(new File("passes/coupons.raw/pass2.json"), PKPass.class);

                float newAmount = getNewRandomAmount();
                PKStoreCard storeCard = pass.getStoreCard();
                List<PKField> primaryFields = storeCard.getPrimaryFields();
                for (PKField field : primaryFields) {
                    if ("balance".equals(field.getKey())) {
                        field.setValue(newAmount);
                        field.setChangeMessage("Amount changed to %@");
                        break;
                    }

                }
                List<PKField> headerFields = storeCard.getHeaderFields();
                for (PKField field : headerFields) {
                    if ("balanceHeader".equals(field.getKey())) {
                        field.setValue(newAmount);
                        break;
                    }

                }

            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            GetPKPassResponse getPKPassResponse = new GetPKPassResponse(pass, new Date());

            return getPKPassResponse;
        }

        private float getNewRandomAmount() {
            Random random = new Random();
            float amount = random.nextInt(100) + random.nextFloat();
            BigDecimal bigDecimalForRounding = new BigDecimal(amount).setScale(2, RoundingMode.HALF_EVEN);
            return bigDecimalForRounding.floatValue();
        }

        @Override
        protected PKSigningInformation getSingingInformation() {
            try {
                return PKSigningUtil.loadSigningInformationFromPKCS12FileAndIntermediateCertificateFile(
                        PKCS12_FILE_PATH, PKCS12_FILE_PASSWORD, APPLE_WWDRCA_CERT_PATH);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

    };
}

From source file:libra.common.kmermatch.KmerJoiner.java

public float getProgress() {
    if (this.progressKey == null) {
        if (this.eof) {
            return 1.0f;
        } else {// ww  w  .j  a v a2 s. c o  m
            return 0.0f;
        }
    } else {
        BigInteger seq = SequenceHelper.convertToBigInteger(this.progressKey.getSequence());
        BigInteger prog = seq.subtract(this.beginSequence);
        int comp = this.partitionSize.compareTo(prog);
        if (comp <= 0) {
            return 1.0f;
        } else {
            BigDecimal progDecimal = new BigDecimal(prog);
            BigDecimal rate = progDecimal.divide(new BigDecimal(this.partitionSize), 3,
                    BigDecimal.ROUND_HALF_UP);

            float f = rate.floatValue();
            return Math.min(1.0f, f);
        }
    }
}

From source file:br.usp.icmc.gazetteer.SemanticSearchTest.Grafico.java

private XYDataset createDataset1() {
    XYSeriesCollection xySeriesCollection = new XYSeriesCollection();
    XYSeries team1_xy_data = new XYSeries("MAP1");
    int k = 126;/*from w  w  w. j  ava  2s  . c o  m*/
    for (BigDecimal d : cm.getMapQ()) {
        team1_xy_data.add(k, d.floatValue());
        k++;
    }
    xySeriesCollection.addSeries(team1_xy_data);
    return xySeriesCollection;
}

From source file:br.usp.icmc.gazetteer.SemanticSearchTest.Grafico.java

private XYDataset createDataset2() {
    XYSeriesCollection xySeriesCollection = new XYSeriesCollection();
    XYSeries team1_xy_data = new XYSeries("MAP2");
    int k = 126;//from  w  ww.j  av a2 s.c o m
    for (BigDecimal d : cm.getFire()) {
        team1_xy_data.add(k, d.floatValue());
        k++;
    }
    xySeriesCollection.addSeries(team1_xy_data);
    return xySeriesCollection;
}

From source file:org.eclipse.smarthome.config.core.Configuration.java

public <T> T as(Class<T> configurationClass) {
    synchronized (this) {

        T configuration = null;//from  w w w .  j  av a 2s .  c  o m

        try {
            configuration = configurationClass.newInstance();
        } catch (InstantiationException | IllegalAccessException ex) {
            logger.error("Could not create configuration instance: " + ex.getMessage(), ex);
            return null;
        }

        List<Field> fields = getAllFields(configurationClass);
        for (Field field : fields) {
            String fieldName = field.getName();
            String typeName = field.getType().getSimpleName();
            Object value = properties.get(fieldName);

            if (value == null && field.getType().isPrimitive()) {
                logger.debug("Skipping field '{}', because it's primitive data type and value is not set",
                        fieldName);
                continue;
            }

            try {
                if (value != null && value instanceof BigDecimal && !typeName.equals("BigDecimal")) {
                    BigDecimal bdValue = (BigDecimal) value;
                    if (typeName.equalsIgnoreCase("Float")) {
                        value = bdValue.floatValue();
                    } else if (typeName.equalsIgnoreCase("Double")) {
                        value = bdValue.doubleValue();
                    } else if (typeName.equalsIgnoreCase("Long")) {
                        value = bdValue.longValue();
                    } else if (typeName.equalsIgnoreCase("Integer") || typeName.equalsIgnoreCase("int")) {
                        value = bdValue.intValue();
                    }
                }

                if (value != null) {
                    logger.debug("Setting value ({}) {} to field '{}' in configuration class {}", typeName,
                            value, fieldName, configurationClass.getName());
                    FieldUtils.writeField(configuration, fieldName, value, true);
                }
            } catch (Exception ex) {
                logger.warn("Could not set field value for field '" + fieldName + "': " + ex.getMessage(), ex);
            }
        }

        return configuration;
    }
}

From source file:org.codhaus.groovy.grails.validation.ScaleConstraint.java

/**
 * {@inheritDoc}/*from  w w  w.  j  av a  2  s  . c om*/
 *
 *     Object, Object, org.springframework.validation.Errors)
 */
@Override
protected void processValidate(Object target, Object propertyValue, Errors errors) {
    BigDecimal bigDecimal;

    BeanWrapper bean = new BeanWrapperImpl(target);

    if (propertyValue instanceof Float) {
        bigDecimal = new BigDecimal(propertyValue.toString());
        bigDecimal = getScaledValue(bigDecimal);
        bean.setPropertyValue(getPropertyName(), bigDecimal.floatValue());
    } else if (propertyValue instanceof Double) {
        bigDecimal = new BigDecimal(propertyValue.toString());
        bigDecimal = getScaledValue(bigDecimal);
        bean.setPropertyValue(getPropertyName(), bigDecimal.doubleValue());
    } else if (propertyValue instanceof BigDecimal) {
        bigDecimal = (BigDecimal) propertyValue;
        bigDecimal = getScaledValue(bigDecimal);
        bean.setPropertyValue(getPropertyName(), bigDecimal);
    } else {
        throw new IllegalArgumentException("Unsupported type detected in constraint [" + getName()
                + "] of property [" + constraintPropertyName + "] of class [" + constraintOwningClass + "]");
    }
}

From source file:com.twitter.elephantbird.pig.load.HBaseSlice.java

@Override
public float getProgress() throws IOException {

    // No way to know max.. just return 0. Sorry, reporting on the last slice is janky.
    // So is reporting on the first slice, by the way -- it will start out too high, possibly at 100%.
    if (endRow_.length == 0)
        return 0;
    byte[] lastPadded = m_lastRow_;
    if (m_lastRow_.length < endRow_.length) {
        lastPadded = Bytes.padTail(m_lastRow_, endRow_.length - m_lastRow_.length);
    }/*from  w  w w .j  a  va2  s  . c o  m*/
    if (m_lastRow_.length < startRow_.length) {
        lastPadded = Bytes.padTail(m_lastRow_, startRow_.length - m_lastRow_.length);
    }
    byte[] prependHeader = { 1, 0 };
    BigInteger bigLastRow = new BigInteger(Bytes.add(prependHeader, lastPadded));
    BigDecimal processed = new BigDecimal(bigLastRow.subtract(bigStart_));
    try {
        BigDecimal progress = processed.setScale(3).divide(bigRange_, BigDecimal.ROUND_HALF_DOWN);
        return progress.floatValue();
    } catch (java.lang.ArithmeticException e) {
        return 0;
    }
}