List of usage examples for java.lang Float toString
public static String toString(float f)
From source file:hr.diskobolos.service.impl.EvaluationAnswerServiceImpl.java
private Float getQuestionnairePercentage(List<EvaluationAnswer> evaluationAnswers, Long numberOfQuestion, List<EvaluationQuestionnaireDefEnum> questionnaireDef) { Long numberOfAnsweredQuestions = evaluationAnswers.stream() .filter(e -> questionnaireDef.contains(e.getAnswer().getEvaluationQuestionDef().getQuestion())) .collect(Collectors.counting()); Float questionnairePercentage = ((float) numberOfAnsweredQuestions / numberOfQuestion) * 100; return new BigDecimal(Float.toString(questionnairePercentage)).setScale(2, BigDecimal.ROUND_HALF_UP) .floatValue();/* ww w. jav a2 s .c o m*/ }
From source file:org.eclipse.gyrex.context.internal.preferences.GyrexContextPreferencesImpl.java
@Override public void putFloat(final String qualifier, final String key, final float value, final boolean encrypt) throws SecurityException { put(qualifier, key, Float.toString(value), context, encrypt); }
From source file:name.setup.dance.DanceStepApp.java
public void postHTTP(String id, String name, int steps, float km) { // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://www.setup.nl/tools/dancestep_app/post/write.php"); try {/* w w w . j a v a 2 s . c om*/ // Add your data List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4); nameValuePairs.add(new BasicNameValuePair("id", id)); nameValuePairs.add(new BasicNameValuePair("name", name)); nameValuePairs.add(new BasicNameValuePair("steps", Integer.toString(steps))); nameValuePairs.add(new BasicNameValuePair("km", Float.toString(km))); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request httpclient.execute(httppost); } catch (ClientProtocolException e) { // TODO Auto-generated catch block } catch (IOException e) { // TODO Auto-generated catch block } }
From source file:edu.cornell.mannlib.vitro.webapp.dao.jena.JenaBaseDao.java
/** * convenience method for use with functional properties *//*from w w w.j a va 2 s .c o m*/ protected void updatePropertyFloatValue(Resource res, Property dataprop, Float value, Model model) { if (dataprop != null) { Float existingValue = null; Statement stmt = res.getProperty(dataprop); if (stmt != null) { RDFNode object = stmt.getObject(); if (object != null && object.isLiteral()) { existingValue = ((Literal) object).getFloat(); } } if (value == null) { model.removeAll(res, dataprop, null); } else if (existingValue == null) { model.add(res, dataprop, Float.toString(value), XSDDatatype.XSDfloat); } else if (existingValue.compareTo(value) != 0) { model.removeAll(res, dataprop, null); model.add(res, dataprop, Float.toString(value), XSDDatatype.XSDfloat); } } }
From source file:edu.ku.brc.af.prefs.AppPreferences.java
/** * Returns the value as a Float./* w w w .j a va 2 s .c o m*/ * @param name the name * @param defaultValue the default value * @return the value as a Float */ public Float getFloat(final String name, final Float defaultValue) { String val = get(name, (defaultValue == null ? null : Float.toString(defaultValue))); return val == null ? null : Float.valueOf(val); }
From source file:org.apache.hadoop.mapreduce.TestMapCollection.java
@Test public void testPostSpillMeta() throws Exception { // write larger records until spill, then write records that generate // no writes into the serialization buffer Configuration conf = new Configuration(); conf.setInt(Job.COMPLETION_POLL_INTERVAL_KEY, 100); Job job = Job.getInstance(conf);/*from w w w. jav a 2 s.co m*/ conf = job.getConfiguration(); conf.setInt(MRJobConfig.IO_SORT_MB, 1); // 2^20 * spill = 14336 bytes available post-spill, at most 896 meta conf.set(MRJobConfig.MAP_SORT_SPILL_PERCENT, Float.toString(.986328125f)); conf.setClass("test.mapcollection.class", StepFactory.class, RecordFactory.class); StepFactory.setLengths(conf, 4000, 0, 96, 0, 252); conf.setInt("test.spillmap.records", 1000); conf.setBoolean("test.disable.key.read", true); conf.setBoolean("test.disable.val.read", true); runTest("postspillmeta", job); }
From source file:jp.co.acroquest.jsonic.Formatter.java
public boolean format(final JSON json, final Context context, final Object src, final Object o, final OutputSource out) throws Exception { NumberFormat f = context.getNumberFormat(); float[] array = (float[]) o; out.append('['); for (int i = 0; i < array.length; i++) { if (Float.isNaN(array[i]) || Float.isInfinite(array[i])) { if (context.getMode() != Mode.SCRIPT) { out.append('"'); out.append(Float.toString(array[i])); out.append('"'); } else if (Double.isNaN(array[i])) { out.append("Number.NaN"); } else { out.append("Number."); out.append((array[i] > 0) ? "POSITIVE" : "NEGATIVE"); out.append("_INFINITY"); }//w ww . ja v a2 s . co m } else if (f != null) { StringFormatter.serialize(context, f.format(array[i]), out); } else { out.append(String.valueOf(array[i])); } if (i != array.length - 1) { out.append(','); if (context.isPrettyPrint()) out.append(' '); } } out.append(']'); return true; }
From source file:no.abmu.abmstatistikk.annualstatistic.service.hibernate2.AnnualStatisticServiceImpl.java
public Report getVirtualReport(long organisationId, String schemaShortName, int year, Set subOrganisationReports) { if (subOrganisationReports == null || subOrganisationReports.isEmpty()) { return null; }//from w w w . j a v a2s .c o m Report virtualReport = newReport(organisationId, schemaShortName, year); ReportHelper virtualReportHelper = new ReportHelper(virtualReport); Set virtualAnswers = virtualReport.getAnswers(); Iterator subReportIterator = subOrganisationReports.iterator(); while (subReportIterator.hasNext()) { Report subReport = (Report) subReportIterator.next(); ReportHelper subReportHelper = new ReportHelper(subReport); Iterator virtualAnswerIterator = virtualAnswers.iterator(); while (virtualAnswerIterator.hasNext()) { Answer virtualAnswer = (Answer) virtualAnswerIterator.next(); Field virtualField = virtualAnswer.getField(); if (virtualField == null) { logger.error("Answer without field."); continue; } FieldType virtualFieldType = virtualField.getFieldType(); if (virtualFieldType == null) { logger.error("Answer without fieldType."); continue; } String virtualDataType = virtualFieldType.getDatatype(); if (virtualDataType != null && (virtualDataType.startsWith("DIGIT") || virtualDataType.startsWith("FLOAT") || virtualDataType.equals("YEARHOURS") || virtualDataType.equals("YEARDAYS") || virtualDataType.equals("WEEKHOURS") || virtualDataType.equals("AUTOCALCULATE"))) { Answer subAnswer = subReportHelper.getAnswerByFieldName(virtualField.getName()); try { float virtualValue = Float.parseFloat(virtualAnswer.getValue()); float subValue = Float.parseFloat(subAnswer.getValue()); virtualValue += subValue; virtualAnswer.setValue(Float.toString(virtualValue)); } catch (NumberFormatException e) { virtualAnswer.setValue("ERROR"); } } } } return virtualReport; }
From source file:ca.nengo.model.impl.ProjectionImpl.java
String getFunctionScript(DecodedOrigin dOrigin) throws ScriptGenException { StringBuilder funcString = new StringBuilder(); boolean first = true; boolean allIdentity = true; for (Function f : dOrigin.getFunctions()) { if (!(f instanceof IdentityFunction)) { allIdentity = false;//from w w w. jav a2s. com break; } } if (!allIdentity) { for (Function f : dOrigin.getFunctions()) { String exp; if (f instanceof PostfixFunction) { PostfixFunction pf = (PostfixFunction) f; exp = pf.getExpression(); exp = exp.replaceAll("\\^", "**"); exp = exp.replaceAll("!", " not "); exp = exp.replaceAll("&", " and "); exp = exp.replaceAll("\\|", " or "); exp = exp.replaceAll("ln", "log"); for (int j = 0; j < f.getDimension(); j++) { String find = "x" + Integer.toString(j); String replace = "x[" + Integer.toString(j) + "]"; exp = exp.replaceAll(find, replace); } } else if (f instanceof IdentityFunction) { exp = "x[" + Integer.toString(((IdentityFunction) f).getIdentityDimension()) + "]"; } else if (f instanceof ConstantFunction) { exp = Float.toString(((ConstantFunction) f).getValue()); } else { throw new ScriptGenException( "Trying to generate script of non user-defined function on an origin which is not supported."); } if (first) { funcString.append(exp); first = false; } else { funcString.append(", " + exp); } } } return funcString.toString(); }
From source file:org.fudgemsg.wire.xml.FudgeXMLStreamWriter.java
private void writeArray(final float[] array) throws XMLStreamException { boolean first = true; for (float value : array) { if (first) first = false;// w w w . j av a 2 s. c om else getWriter().writeCharacters(","); getWriter().writeCharacters(Float.toString(value)); } }