Java Code Examples for org.apache.commons.lang3.math.NumberUtils#toDouble()
The following examples show how to use
org.apache.commons.lang3.math.NumberUtils#toDouble() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExpressionParser.java From vscrawler with Apache License 2.0 | 6 votes |
private SyntaxNode buildByTokenHolder(TokenHolder tokenHolder) { if (tokenHolder.tokenType == TokenType.Expression) { return new ExpressionParser(new StringFunctionTokenQueue(tokenHolder.data)).parse(); } if (tokenHolder.tokenType == TokenType.Function) { return parseFunction(new StringFunctionTokenQueue(tokenHolder.data)); } if (tokenHolder.tokenType == TokenType.String) { return new StringSyntaxNode(tokenHolder.data); } if (tokenHolder.tokenType == TokenType.Boolean) { return new BooleanSyntaxNode(BooleanUtils.toBoolean(tokenHolder.data)); } if (tokenHolder.tokenType == TokenType.Number) { if (tokenHolder.data.contains(".")) { return new NumberSyntaxNode(NumberUtils.toDouble(tokenHolder.data)); } else { return new NumberSyntaxNode(NumberUtils.toInt(tokenHolder.data)); } } throw new IllegalStateException("unknown token type: " + tokenHolder.tokenType); }
Example 2
Source File: OXRCurrencyConverter.java From para with Apache License 2.0 | 6 votes |
@Override public Double convertCurrency(Number amount, String from, String to) { if (amount == null || StringUtils.isBlank(from) || StringUtils.isBlank(to)) { return 0.0; } Sysprop s = dao.read(FXRATES_KEY); if (s == null) { s = fetchFxRatesJSON(); } else if ((Utils.timestamp() - s.getTimestamp()) > REFRESH_AFTER) { // lazy refresh fx rates Para.asyncExecute(new Runnable() { public void run() { fetchFxRatesJSON(); } }); } double ratio = 1.0; if (s.hasProperty(from) && s.hasProperty(to)) { Double f = NumberUtils.toDouble(s.getProperty(from).toString(), 1.0); Double t = NumberUtils.toDouble(s.getProperty(to).toString(), 1.0); ratio = t / f; } return amount.doubleValue() * ratio; }
Example 3
Source File: RuleResolverImpl.java From smockin with Apache License 2.0 | 6 votes |
boolean handleEquals(RestfulMockDefinitionRuleGroupCondition condition, final String inboundValue) { if (inboundValue == null) { return false; } final RuleDataTypeEnum ruleMatchDataType = condition.getDataType(); final String ruleMatchValue = condition.getMatchValue(); if (RuleDataTypeEnum.TEXT.equals(ruleMatchDataType)) { if (condition.isCaseSensitive() != null && condition.isCaseSensitive()) { return ruleMatchValue.equals(inboundValue); } return ruleMatchValue.equalsIgnoreCase(inboundValue); } else if (RuleDataTypeEnum.NUMERIC.equals(ruleMatchDataType) && NumberUtils.isCreatable(inboundValue) && NumberUtils.toDouble(inboundValue) == NumberUtils.toDouble(ruleMatchValue)) { return true; } return false; }
Example 4
Source File: ComWorkflowEQLHelper.java From openemm with GNU Affero General Public License v3.0 | 6 votes |
private String generateNumericEQL(String resolvedFieldName, int operator, String value, int operator2, String value2, boolean disableThreeValuedLogic) throws EQLCreationException { TargetOperator targetOperator = getValidOperator(TargetNodeNumeric.getValidOperators(), operator); TargetOperator targetOperator2 = getValidOperator(TargetNodeNumeric.getValidOperators(), operator2); if (targetOperator == null || targetOperator == TargetNode.OPERATOR_MOD && targetOperator2 == null) { throw new EQLCreationException("No or invalid primary operator defined"); } if(targetOperator == OPERATOR_IS) { return String.format("%s %s", resolvedFieldName, EqlUtils.getIsEmptyOperatorValue(value)); } double floatValue = NumberUtils.toDouble(value, 0.0f); value = DECIMAL_FORMAT.format(floatValue); if (targetOperator == TargetNode.OPERATOR_MOD) { double floatValue2 = NumberUtils.toDouble(value2, 0.0f); value2 = DECIMAL_FORMAT.format(floatValue2); return EqlUtils.makeEquation(resolvedFieldName, targetOperator, value, targetOperator2, value2, disableThreeValuedLogic); } else { return EqlUtils.makeEquation(resolvedFieldName, targetOperator, value, disableThreeValuedLogic); } }
Example 5
Source File: Query.java From conductor with Apache License 2.0 | 5 votes |
protected Double convertDouble(Object value) { if (null == value) { return null; } if (value instanceof Double) { return (Double) value; } if (value instanceof Number) { return ((Number) value).doubleValue(); } return NumberUtils.toDouble(value.toString()); }
Example 6
Source File: RestUtils.java From para with Apache License 2.0 | 5 votes |
private static <P extends ParaObject> List<P> findNearbyQuery(MultivaluedMap<String, String> params, String appid, String type, String query, Pager pager) { String latlng = params.getFirst("latlng"); if (StringUtils.contains(latlng, ",")) { String[] coords = latlng.split(",", 2); String rad = paramOrDefault(params, "radius", null); int radius = NumberUtils.toInt(rad, 10); double lat = NumberUtils.toDouble(coords[0], 0); double lng = NumberUtils.toDouble(coords[1], 0); return Para.getSearch().findNearby(appid, type, query, radius, lat, lng, pager); } return Collections.emptyList(); }
Example 7
Source File: Query.java From conductor with Apache License 2.0 | 5 votes |
protected Double convertDouble(Object value) { if (null == value) { return null; } if (value instanceof Double) { return (Double) value; } if (value instanceof Number) { return ((Number) value).doubleValue(); } return NumberUtils.toDouble(value.toString()); }
Example 8
Source File: ObjectUtils.java From frpMgr with MIT License | 5 votes |
/** * 转换为Double类型 */ public static Double toDouble(final Object val) { if (val == null) { return 0D; } try { return NumberUtils.toDouble(StringUtils.trim(val.toString())); } catch (Exception e) { return 0D; } }
Example 9
Source File: Row.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
/** 统计计算时用于转换值,不可转换的值默认为0 */ public Double getAsDouble(String key) { Object o = this.data.get(key); String val = Objects.toString(o, ""); if (NumberUtils.isCreatable(val)) { return NumberUtils.toDouble(val); } else { return 0d; } }
Example 10
Source File: Row.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
@SuppressWarnings("deprecation") public Double getAsDouble(String key) { Object o = this.data.get(key); String val = Objects.toString(o, ""); if (NumberUtils.isNumber(val)) { return NumberUtils.toDouble(val); } else { return 0d; } }
Example 11
Source File: RedisNumber.java From azeroth with Apache License 2.0 | 4 votes |
public Double getDouble() { String value = super.get(); return value == null ? null : NumberUtils.toDouble(value); }
Example 12
Source File: ConfigUtils.java From fastjgame with Apache License 2.0 | 4 votes |
public static double getAsDouble(final String str, final double defaultValue) { return NumberUtils.toDouble(str, defaultValue); }
Example 13
Source File: NumberUtil.java From j360-dubbo-app-all with Apache License 2.0 | 4 votes |
/** * 将10进制的String安全的转化为double,当str为空或非数字字符串时,返回0 */ public static double toDouble(String str) { return NumberUtils.toDouble(str, 0L); }
Example 14
Source File: NumberUtil.java From j360-dubbo-app-all with Apache License 2.0 | 4 votes |
/** * 将10进制的String安全的转化为double,当str为空或非数字字符串时,返回default值 */ public static double toDouble(String str, double defaultValue) { return NumberUtils.toDouble(str, defaultValue); }
Example 15
Source File: RedisNumber.java From jeesuite-libs with Apache License 2.0 | 4 votes |
public Double getDouble() { String value = super.get(); return value == null ? null : NumberUtils.toDouble(value); }
Example 16
Source File: AssignmentGradeComparator.java From sakai with Educational Community License v2.0 | 3 votes |
@Override public int compare(final GbStudentGradeInfo g1, final GbStudentGradeInfo g2) { final GbGradeInfo info1 = g1.getGrades().get(this.assignmentId); final GbGradeInfo info2 = g2.getGrades().get(this.assignmentId); // for proper number ordering, these have to be numerical final Double grade1 = (info1 != null) ? NumberUtils.toDouble(info1.getGrade()) : null; final Double grade2 = (info2 != null) ? NumberUtils.toDouble(info2.getGrade()) : null; return new CompareToBuilder().append(grade1, grade2).toComparison(); }
Example 17
Source File: AssignmentGradeComparator.java From sakai with Educational Community License v2.0 | 3 votes |
@Override public int compare(final GbStudentGradeInfo g1, final GbStudentGradeInfo g2) { final GbGradeInfo info1 = g1.getGrades().get(this.assignmentId); final GbGradeInfo info2 = g2.getGrades().get(this.assignmentId); // for proper number ordering, these have to be numerical final Double grade1 = (info1 != null) ? NumberUtils.toDouble(info1.getGrade()) : null; final Double grade2 = (info2 != null) ? NumberUtils.toDouble(info2.getGrade()) : null; return new CompareToBuilder().append(grade1, grade2).toComparison(); }
Example 18
Source File: NumberUtil.java From vjtools with Apache License 2.0 | 2 votes |
/** * 将10进制的String安全的转化为double. * * 当str为空或非数字字符串时,返回default值 */ public static double toDouble(@Nullable String str, double defaultValue) { return NumberUtils.toDouble(str, defaultValue); }
Example 19
Source File: Config.java From para with Apache License 2.0 | 2 votes |
/** * Returns the double value of a configuration parameter. * @param key the param key * @param defaultValue the default param value * @return the value of a param */ public static double getConfigDouble(String key, double defaultValue) { return NumberUtils.toDouble(getConfigParam(key, Double.toString(defaultValue))); }
Example 20
Source File: NumberUtil.java From vjtools with Apache License 2.0 | 2 votes |
/** * 将10进制的String安全的转化为double. * * 当str为空或非数字字符串时,返回default值 */ public static double toDouble(@Nullable String str, double defaultValue) { return NumberUtils.toDouble(str, defaultValue); }