Example usage for java.lang Float toString

List of usage examples for java.lang Float toString

Introduction

In this page you can find the example usage for java.lang Float toString.

Prototype

public static String toString(float f) 

Source Link

Document

Returns a string representation of the float argument.

Usage

From source file:no.abmu.abmstatistikk.annualstatistic.service.AnswerHelper.java

public void autoCalculate() {
    float sum = 0;
    Field field = answer.getField();
    if (field == null) {
        logger.error("No field for answer: " + answer);
    }/*from  w  ww . j  a v  a 2 s. co m*/
    if (logger.isDebugEnabled()) {
        logger.debug("Calculating sum for field " + field.getName());
    }
    FieldType fieldType = field.getFieldType();
    if (!fieldType.getDatatype().equals("AUTOCALCULATE")) {
        logger.error("Trying to autocalculate an answer of type " + fieldType.getDatatype() + " - " + answer);
        return;
    }

    String oldValue = answer.getValue();
    if (oldValue != null && (!oldValue.equals("") || oldValue.equals("CALCULATING"))) {
        /* This sum has allready been calculated */
        return; /* Early cutoff in recursive sums */
    }
    answer.setValue("CALCULATING");

    Report report = answer.getReport();
    if (report == null) {
        logger.error("Answer not bound to a report: " + answer);
    }
    ReportHelper reportHelper = new ReportHelper(report);
    Set fieldGroupMemberships = field.getFieldGroupConstraintMembers();
    if (fieldGroupMemberships.isEmpty()) {
        logger.error("Trying to autocalculate answer for field " + field.getName() + " with no Fieldgroup "
                + "membership " + answer);
    }

    Iterator fieldGroupMembershipsIterator = fieldGroupMemberships.iterator();
    while (fieldGroupMembershipsIterator.hasNext()) {
        FieldGroupConstraintMember groupMembership = (FieldGroupConstraintMember) fieldGroupMembershipsIterator
                .next();
        FieldGroupConstraint groupConstraint = groupMembership.getFieldGroupConstraint();
        String groupConstraintType = groupConstraint.getType();
        if (groupConstraintType.equals("CALCULATION")) {
            FieldGroupConstraintHelper constraintHelper = new FieldGroupConstraintHelper(groupConstraint);
            int orderInGroup = groupMembership.getComp_id().getOrderingroupconstraint().intValue();
            if (orderInGroup == 0) {
                int lastMemberNumber = constraintHelper.lastMemberNumber();
                String sign = groupConstraint.getParameter();
                if (sign == null
                        || (!sign.equals("+") && !sign.equals("-") && !sign.equals("*") && !sign.equals("/"))) {
                    logger.error("Don't know how to calculate with '" + sign + "'.");
                    return;
                }
                for (int i = 1; i <= lastMemberNumber; i++) {
                    String sumMemberFieldName = constraintHelper.getFieldNameByOrderInGroup(i);
                    Answer sumMember = reportHelper.getAnswerByFieldName(sumMemberFieldName);
                    if (sumMember == null) {
                        logger.error("Report for schema " + report.getSchema().getShortname()
                                + " has no field with name " + sumMemberFieldName + ".");
                        logger.error("Cannot calculate sum for field " + field.getName());
                        return;
                    }

                    /* If field is autocalculated, calculate it first */
                    Field sumMemberField = sumMember.getField();
                    if (sumMemberField == null) {
                        logger.error("Member in sum has no field: " + sumMember);
                        return;
                    }
                    FieldType sumMemberFieldType = sumMemberField.getFieldType();
                    if (sumMemberFieldType == null) {
                        logger.error("Member in sum has noe fieldtype: " + answer);
                        return;
                    }
                    if (sumMemberFieldType.getDatatype().equals("AUTOCALCULATE")) {
                        AnswerHelper sumMemberHelper = new AnswerHelper(sumMember);
                        String calculateValue = sumMember.getValue();
                        if (calculateValue != null && calculateValue.equals("CALCULATING")) {
                            logger.error("Calculation loop detected when " + "calculating sum for field "
                                    + field.getName() + " in report for schema "
                                    + report.getSchema().getShortname());
                            return;
                        }
                        sumMemberHelper.autoCalculate();
                    }

                    float sumMemberValue = 0;
                    String value = sumMember.getValue();
                    if (value == null || value.equals("")) {
                        continue;
                    }
                    try {
                        sumMemberValue = Float.parseFloat(value);
                    } catch (NumberFormatException e) {
                        /* Badly formated number. Should not happen, return
                         * with answer.value == null.
                         */
                        answer.setValue("ERROR");
                        return;
                    }
                    if (i == 1) { /* Start with sum equals to first member*/
                        sum = sumMemberValue;
                    } else if (sign.equals("+")) {
                        sum += sumMemberValue;
                    } else if (sign.equals("-")) {
                        sum -= sumMemberValue;
                    } else if (sign.equals("*")) {
                        sum *= sumMemberValue;
                    } else if (sign.equals("/")) {
                        sum /= sumMemberValue;
                    } else {
                        logger.error("Bad calculation! " + "Should never reach this point");
                        return;
                    }
                }

                if (logger.isDebugEnabled()) {
                    logger.debug("Calculated sum for field " + answer.getField().getName() + " with value "
                            + Float.toString(sum));
                }

                answer.setValue(Float.toString(sum));
                return;
            }
        }
    }
    logger.error("Trying to autocalculate answer with no CALCULATION " + "fieldgroups where orderInGroup is 0: "
            + answer);
}

From source file:org.easyrec.soap.nodomain.impl.EasyRecSoap.java

@WebMethod
public ResponseRule importrule(@WebParam(name = "token") String token,
        @WebParam(name = "tenantid") String tenantId, @WebParam(name = "itemfromid") String itemfromid,
        @WebParam(name = "itemtoid") String itemtoid, @WebParam(name = "assocvalue") String assocvalue,
        @WebParam(name = "assoctype") String assoctype) throws EasyRecSoapException {

    Item itemfrom = null;//  w w  w.j a  va  2s .  c  o  m
    Item itemto = null;
    Float assocValue = null;
    Integer assocTypeId = null;
    Integer coreTenantId = null;

    // Collect a List of messages for the user to understand,
    // what went wrong (e.g. Wrong API key).
    List<Message> messages = new ArrayList<Message>();

    Operator o = operatorDAO.getOperatorFromToken(token);
    if (o != null) {

        coreTenantId = operatorDAO.getTenantId(o.getApiKey(), tenantId);

        if (itemfromid != null && itemfromid.equals(itemtoid)) {
            messages.add(MSG.ITEMFROM_EQUAL_ITEMTO);
        }

        RemoteTenant r = remoteTenantDAO.get(coreTenantId);
        if (r != null) {

            itemfrom = itemDAO.get(r, itemfromid, Item.DEFAULT_STRING_ITEM_TYPE);
            if (itemfrom == null) {
                messages.add(MSG.ITEM_FROM_ID_DOES_NOT_EXIST);
            }

            itemto = itemDAO.get(r, itemtoid, Item.DEFAULT_STRING_ITEM_TYPE);
            if (itemto == null) {
                messages.add(MSG.ITEM_TO_ID_DOES_NOT_EXIST);
            }

            try {
                assocTypeId = typeMappingService.getIdOfAssocType(coreTenantId, assoctype);
            } catch (Exception e) {
                messages.add(MSG.ASSOC_TYPE_DOES_NOT_EXIST);
            }

        } else {
            messages.add(MSG.TENANT_WRONG_TENANT);
        }
        try {
            assocValue = Float.parseFloat(assocvalue);
            if (assocValue < 0 || assocValue > 100) {
                messages.add(MSG.INVALID_ASSOC_VALUE);
            }
        } catch (Exception e) {
            messages.add(MSG.INVALID_ASSOC_VALUE);
        }

    } else {
        messages.add(MSG.WRONG_TOKEN);
    }

    if (messages.size() > 0) {
        throw new EasyRecSoapException(messages, WS.ACTION_IMPORT_RULE);
    }

    remoteAssocService.addRule(coreTenantId, itemfromid, null, itemtoid, null, assocTypeId, assocValue);

    return new ResponseRule(tenantId, WS.ACTION_IMPORT_RULE, itemfrom.getItemId(), itemto.getItemId(),
            assoctype, Float.toString(assocValue));
}

From source file:eu.optimis.service_manager.rest.ServiceManagerREST.java

/**
 * Returns the initial cost value of an infrastructure provider.
 * <p/>/*ww  w.  j a  va  2s  . c  om*/
 * This operation is exposed through this URL:
 * <p/>
 * <code>/services/{serviceId}/ip/initialcostvalue</code>
 * 
 * @param serviceId
 *            the id of the service
 * 
 * @param ipId
 *            the infrastructure provider id
 * 
 * @return initial cost value
 */
@GET
@Path("/services/{serviceId}/{ipId}/initialcostvalue")
public String getInitialCostValue(@PathParam("serviceId") String serviceId, @PathParam("ipId") String ipId) {
    LOGGER.debug("ServiceManagerREST: getInitialCostValue() called for serviceId: " + serviceId + " with ipId: "
            + ipId);
    float initialCostValue;
    try {
        initialCostValue = serviceManager.getInitialCostValue(serviceId, ipId);

    } catch (ItemNotFoundException itemNotFoundException) {
        LOGGER.error("ServiceManagerREST: Cannot get infrastructure provider ids for service with id '"
                + serviceId + "': " + itemNotFoundException.getMessage());
        throw new WebApplicationException(Response.Status.NOT_FOUND);
    }
    return Float.toString(initialCostValue);
}

From source file:Logica.Usuario.java

/**
 *
 * @param i/*from  ww w  .  jav a  2 s . c o  m*/
 * @return
 * @throws RemoteException
 */
@Override
public ArrayList<itemxproveedor> getProveedorAsociado(itemxproveedor i) throws RemoteException {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    String cinterno = i.getCinterno();
    Double precio = new Double(Float.toString(i.getPrecio()));
    EntityManager em = emf.createEntityManager();
    Query q = em.createNamedQuery("Ixp.findByCinterno_Precio");
    q.setParameter("cinterno", cinterno);
    q.setParameter("precio", precio);
    List<Ixp> resultList = q.getResultList();
    ArrayList<itemxproveedor> retorno = new ArrayList<>();
    if (!resultList.isEmpty()) {
        for (Ixp ixp : resultList) {
            proveedor datosProveedor = this.getDatosProveedor(ixp.getNit());
            itemxproveedor itx = new itemxproveedor(datosProveedor.getNombre(), new Float(ixp.getPrecio()),
                    ixp.getCinterno());
            itx.setNIT(ixp.getNit());
            retorno.add(itx);
        }
    }
    emf.close();
    return retorno;

}

From source file:Logica.Usuario.java

@Override
public boolean desaprobarItems(ArrayList<ItemInventario> itemsSolicitud, solicitudPr sol,
        ArrayList<String> proveedor) throws RemoteException {
    boolean itxActualizado = false;
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    ArrayList<ItemInventario> itemsAprobado = this.getItemsAprobado(sol.getNum_sol(), "SI");
    ArrayList<ItemInventario> itemsAEditar = new ArrayList<>();
    for (ItemInventario i : itemsSolicitud) {
        for (ItemInventario j : itemsAprobado) {
            if (i.getNumero().equalsIgnoreCase(j.getNumero())) {
                itemsAEditar.add(i);/*from  ww w .  j a  va2 s  . c o m*/
            }
        }
    }
    try {
        EntityManager em = emf.createEntityManager();
        Query q = em.createNamedQuery("Itxsol.findSol_Item");
        q.setParameter("numSol", sol.getNum_sol());
        ItxsolJpaController con = new ItxsolJpaController(emf);
        int indexProv = 0;
        for (ItemInventario item : itemsAEditar) {
            ItemJpaController itemJpaController = new ItemJpaController(emf);
            Item findItem = itemJpaController.findItem(item.getNumero());
            findItem.setPrecio(0.0);
            q.setParameter("cinterno", findItem);
            List<Itxsol> resultList = q.getResultList();
            Itxsol get = resultList.get(0);
            Itxsol found = con.findItxsol(get.getId());
            found.setAprobado("NO");
            found.setCantidadaprobada(0.0);
            found.setGenerado("NO");
            found.setNitProveedor("");
            con.edit(found);
            itxActualizado = true;
            itemJpaController.edit(findItem);
            this.desasociarItem(item.getNumero(), proveedor.get(indexProv), Float.toString(item.getPrecio()));
            indexProv++;
        }
        SolicitudPrJpaController s = new SolicitudPrJpaController(emf);
        SolicitudPr found = s.findSolicitudPr(new Double(sol.getNum_sol().toString()));
        found.setRevisado("NO");
        s.edit(found);

    } catch (Exception ex) {
        Logger.getLogger(Usuario.class.getName()).log(Level.SEVERE, null, ex);
    }
    emf.close();
    return itxActualizado;
}

From source file:org.apache.pdfbox.pdmodel.PDDocument.java

/**
 * Sets the PDF specification version for this document.
 *
 * @param newVersion the new PDF version (e.g. 1.4f)
 * //from   ww  w. java 2  s.  c om
 */
public void setVersion(float newVersion) {
    float currentVersion = getVersion();
    // nothing to do?
    if (newVersion == currentVersion) {
        return;
    }
    // the version can't be downgraded
    if (newVersion < currentVersion) {
        LOG.error("It's not allowed to downgrade the version of a pdf.");
        return;
    }
    // update the catalog version if the document version is >= 1.4
    if (getDocument().getVersion() >= 1.4f) {
        getDocumentCatalog().setVersion(Float.toString(newVersion));
    } else {
        // versions < 1.4f have a version header only
        getDocument().setVersion(newVersion);
    }
}

From source file:eu.itesla_project.online.db.OnlineDbMVStore.java

@Override
public void storeWorkflowParameters(String workflowId, OnlineWorkflowParameters parameters) {
    Objects.requireNonNull(workflowId, "workflow id is null");
    Objects.requireNonNull(parameters, "online workflow parameters is null");
    LOGGER.info("Storing configuration parameters for workflow {}", workflowId);
    MVStore wfMVStore = getStore(workflowId);
    // check if the parameters for this wf have already been stored
    if (wfMVStore.hasMap(STORED_PARAMETERS_MAP_NAME))
        removeWfParameters(workflowId, wfMVStore);
    MVMap<String, String> storedParametersMap = wfMVStore.openMap(STORED_PARAMETERS_MAP_NAME, mapBuilder);
    // store basecase
    storedParametersMap.put(STORED_PARAMETERS_BASECASE_KEY, parameters.getBaseCaseDate().toString());
    // store number of states
    storedParametersMap.put(STORED_PARAMETERS_STATE_NUMBER_KEY, Integer.toString(parameters.getStates()));
    // store interval of historical data
    storedParametersMap.put(STORED_PARAMETERS_HISTO_INTERVAL_KEY, parameters.getHistoInterval().toString());
    // store offline workflow id
    storedParametersMap.put(STORED_PARAMETERS_OFFLINE_WF_ID_KEY, parameters.getOfflineWorkflowId());
    // store time horizon
    storedParametersMap.put(STORED_RESULTS_TIMEHORIZON_KEY, parameters.getTimeHorizon().getName());
    // store forecast error analysis id
    storedParametersMap.put(STORED_PARAMETERS_FEA_ID_KEY, parameters.getFeAnalysisId());
    // store rules purity threshold
    storedParametersMap.put(STORED_PARAMETERS_RULES_PURITY_KEY,
            Double.toString(parameters.getRulesPurityThreshold()));
    // store flag store states
    storedParametersMap.put(STORED_PARAMETERS_STORE_STATES_KEY, Boolean.toString(parameters.storeStates()));
    // store flag analyse basecase
    storedParametersMap.put(STORED_PARAMETERS_ANALYSE_BASECASE_KEY,
            Boolean.toString(parameters.analyseBasecase()));
    // store flag validation
    storedParametersMap.put(STORED_PARAMETERS_VALIDATION_KEY, Boolean.toString(parameters.validation()));
    // store security indexes
    if (parameters.getSecurityIndexes() != null)
        storedParametersMap.put(STORED_PARAMETERS_SECURITY_INDEXES_KEY,
                OnlineDbMVStoreUtils.indexesTypesToJson(parameters.getSecurityIndexes()));
    // store case type
    storedParametersMap.put(STORED_PARAMETERS_CASE_TYPE_KEY, parameters.getCaseType().name());
    // store countries
    storedParametersMap.put(STORED_PARAMETERS_COUNTRIES_KEY,
            OnlineDbMVStoreUtils.countriesToJson(parameters.getCountries()));
    // store merge optimized flag
    storedParametersMap.put(STORED_PARAMETERS_MERGE_OPTIMIZED_KEY,
            Boolean.toString(parameters.isMergeOptimized()));
    // store merge optimized flag
    storedParametersMap.put(STORED_PARAMETERS_LIMIT_REDUCTION_KEY,
            Float.toString(parameters.getLimitReduction()));
    // store handle violations in N flag
    storedParametersMap.put(STORED_PARAMETERS_HANDLE_VIOLATIONS_KEY,
            Boolean.toString(parameters.isHandleViolationsInN()));
    // store merge constraint margin
    storedParametersMap.put(STORED_PARAMETERS_CONSTRAINT_MARGIN_KEY,
            Float.toString(parameters.getConstraintMargin()));
    // store case file name
    if (parameters.getCaseFile() != null) {
        storedParametersMap.put(STORED_PARAMETERS_CASE_FILE_KEY, parameters.getCaseFile());
    }//from  w w  w.  j  av a2s.c o m

    wfMVStore.commit();
}

From source file:joshuatee.wx.USWXOGLRadarActivity.java

@Override
public void onLongPress(MotionEvent event) {

    x = event.getX();//from ww w.  j av a  2 s . co m
    //y=0.0f;
    y = event.getY() - statusBarHeight - actionBarHeight;

    x_middle = screen_width / 2;
    y_middle = (screen_height - statusBarHeight - actionBarHeight) / 2;

    diff_x = density * (x_middle - x) / mScaleFactor;
    diff_y = density * (y_middle - y) / mScaleFactor;

    x_str = preferences.getString("RID_" + rid1 + "_X", "0.00");
    y_str = preferences.getString("RID_" + rid1 + "_Y", "0.00");

    //Float center_x = 0.0f;
    //Float center_y = 0.0f;

    try {
        center_x = Float.parseFloat(x_str);
        center_y = Float.parseFloat(y_str);
    } catch (Exception e) {
    }

    ppd = OGLR.one_degree_scale_factor;
    new_x = center_y + ((OGLR.mPositionX) / mScaleFactor + diff_x) / ppd;
    test2 = 180 / Math.PI * Math.log(Math.tan(Math.PI / 4 + center_x * (Math.PI / 180) / 2));
    new_y = (float) test2 + ((-OGLR.mPositionY) / mScaleFactor + diff_y) / ppd;
    new_y = (float) (180 / Math.PI * (2 * Math.atan(Math.exp(new_y * Math.PI / 180)) - Math.PI / 2));

    rid_tmp = UtilityLocation.GetNearestRid(getBaseContext(), Float.toString(new_y),
            Float.toString(new_x * -1));

    if (!rid1.equals(rid_tmp))
        RIDMapSwitch(rid_tmp);

}

From source file:com.tao.realweb.util.StringUtil.java

/** 
* ,num<=0 ""; /*from  w  w w. jav  a2  s .com*/
*  
* @param num 
* @return 
*/
public static String numberToString(Object num) {
    if (num == null) {
        return null;
    } else if (num instanceof Integer && (Integer) num > 0) {
        return Integer.toString((Integer) num);
    } else if (num instanceof Long && (Long) num > 0) {
        return Long.toString((Long) num);
    } else if (num instanceof Float && (Float) num > 0) {
        return Float.toString((Float) num);
    } else if (num instanceof Double && (Double) num > 0) {
        return Double.toString((Double) num);
    } else {
        return "";
    }
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccDb2LUW.CFAccDb2LUWSchema.java

public static String getFloatString(float val) {
    return (Float.toString(val));
}