List of usage examples for java.lang Number floatValue
public abstract float floatValue();
From source file:com.appunite.rx.android.MoreViewActions.java
@Nonnull public static Action1<? super Number> translateY(@Nonnull final View view) { checkNotNull(view);/*from w w w. j a v a2 s . c o m*/ return new Action1<Number>() { @Override public void call(final Number number) { ViewCompat.setTranslationY(view, number.floatValue()); } }; }
From source file:Main.java
/** * Adopted from http://jgnash.svn.sourceforge.net/viewvc/jgnash/jgnash2/trunk/src/jgnash/imports/qif/QifUtils.java */// w ww .jav a2 s .c o m public static BigDecimal parseMoney(String money) { String sMoney = money; if (sMoney != null) { sMoney = sMoney.trim(); // to be safe try { return new BigDecimal(sMoney); } catch (NumberFormatException e) { /* there must be commas, etc in the number. Need to look for them * and remove them first, and then try BigDecimal again. If that * fails, then give up and use NumberFormat and scale it down * */ String[] split = MONEY_PREFIX_PATTERN.split(sMoney); if (split.length >= 2) { StringBuilder buf = new StringBuilder(); if (sMoney.startsWith("-")) { buf.append('-'); } for (int i = 0; i < split.length - 1; i++) { buf.append(split[i]); } buf.append('.'); buf.append(split[split.length - 1]); try { return new BigDecimal(buf.toString()); } catch (final NumberFormatException e2) { Log.e("QifUtils", "Second parse attempt failed, falling back to rounding"); } } NumberFormat formatter = NumberFormat.getNumberInstance(); try { Number num = formatter.parse(sMoney); return new BigDecimal(num.floatValue()); } catch (ParseException ignored) { } Log.e("QifUtils", "Could not parse money " + sMoney); } } return new BigDecimal(0); }
From source file:org.eclipse.wb.internal.core.eval.evaluators.FloatEvaluator.java
/** * Converts given {@link Expression} into "float" value. *//*w ww .j a v a2 s .c o m*/ private static float getFloatValue(EvaluationContext context, Expression expression) throws Exception { Object value = AstEvaluationEngine.evaluate(context, expression); // Character if (value instanceof Character) { Character character = (Character) value; return character.charValue(); } // Number Number number = (Number) value; return number.floatValue(); }
From source file:Main.java
/** * Adopted from http://jgnash.svn.sourceforge.net/viewvc/jgnash/jgnash2/trunk/src/jgnash/imports/qif/QifUtils.java *//*w ww .j a v a2s . c o m*/ public static long parseMoney(String money) { if (money != null) { BigDecimal bdMoney; money = money.trim(); // to be safe try { bdMoney = new BigDecimal(money); return moneyAsLong(bdMoney); } catch (NumberFormatException e) { /* there must be commas, etc in the number. Need to look for them * and remove them first, and then try BigDecimal again. If that * fails, then give up and use NumberFormat and scale it down * */ String[] split = MONEY_PREFIX_PATTERN.split(money); if (split.length > 1) { StringBuilder buf = new StringBuilder(); if (money.startsWith("-")) { buf.append('-'); } for (int i = 0; i < split.length - 1; i++) { buf.append(split[i]); } buf.append('.'); buf.append(split[split.length - 1]); try { bdMoney = new BigDecimal(buf.toString()); return moneyAsLong(bdMoney); } catch (final NumberFormatException e2) { Log.e("QifUtils", "Second parse attempt failed, falling back to rounding"); } } NumberFormat formatter = NumberFormat.getNumberInstance(); try { Number num = formatter.parse(money); BigDecimal bd = new BigDecimal(num.floatValue()); if (bd.scale() > 6) { bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP); } return moneyAsLong(bd); } catch (ParseException ignored) { } Log.e("QifUtils", "Could not parse money " + money); } } return 0; }
From source file:Main.java
/** * Adopted from http://jgnash.svn.sourceforge.net/viewvc/jgnash/jgnash2/trunk/src/jgnash/imports/qif/QifUtils.java *//*from www .ja v a 2s . com*/ public static long parseMoney(String money) { String sMoney = money; if (sMoney != null) { BigDecimal bdMoney; sMoney = sMoney.trim(); // to be safe try { bdMoney = new BigDecimal(sMoney); return moneyAsLong(bdMoney); } catch (NumberFormatException e) { /* there must be commas, etc in the number. Need to look for them * and remove them first, and then try BigDecimal again. If that * fails, then give up and use NumberFormat and scale it down * */ String[] split = MONEY_PREFIX_PATTERN.split(sMoney); if (split.length > 2) { StringBuilder buf = new StringBuilder(); if (sMoney.startsWith("-")) { buf.append('-'); } for (int i = 0; i < split.length - 1; i++) { buf.append(split[i]); } buf.append('.'); buf.append(split[split.length - 1]); try { bdMoney = new BigDecimal(buf.toString()); return moneyAsLong(bdMoney); } catch (final NumberFormatException e2) { Log.e("QifUtils", "Second parse attempt failed, falling back to rounding"); } } NumberFormat formatter = NumberFormat.getNumberInstance(); try { Number num = formatter.parse(sMoney); BigDecimal bd = new BigDecimal(num.floatValue()); if (bd.scale() > 6) { bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP); } return moneyAsLong(bd); } catch (ParseException ignored) { } Log.e("QifUtils", "Could not parse money " + sMoney); } } return 0; }
From source file:com.fengduo.bee.commons.core.lang.Argument.java
public static boolean isPositive(Number argument) { if (null == argument) { return false; }//w w w. j a v a 2 s . co m return argument.floatValue() > 0f || argument.intValue() > 0; }
From source file:com.mmj.app.common.core.lang.Argument.java
public static boolean isPositive(Number argument) { if (argument == null) { return false; }/*from www. j a v a 2s . c o m*/ return argument.floatValue() > 0f || argument.intValue() > 0; }
From source file:mil.jpeojtrs.sca.util.PrimitiveArrayUtils.java
public static float[] convertToFloatArray(final Object array) { if (array == null) { return null; }/*from w w w . ja va 2s . c om*/ if (array instanceof float[]) { return (float[]) array; } if (array instanceof Float[]) { return ArrayUtils.toPrimitive((Float[]) array); } final float[] newArray = new float[Array.getLength(array)]; for (int i = 0; i < newArray.length; i++) { final Number val = (Number) Array.get(array, i); newArray[i] = val.floatValue(); } return newArray; }
From source file:net.dontdrinkandroot.utils.lang.math.NumberUtils.java
/** * Get the null safe floatValue of a Number. Defaults to 0. * /* ww w.ja va 2s . c o m*/ * @param number * The Number to convert. * @return The null safe floatValue. Defaults to 0. */ public static float floatValue(final Number number) { if (number == null) { return 0; } return number.floatValue(); }
From source file:com.mmj.app.common.util.StringFormatter.java
public static String formatFloat(Number denominator, Number molecule) { if (denominator == null || molecule == null) { return null; }/*from w w w . ja v a2 s . c o m*/ return formatFloat(denominator.floatValue() / molecule.floatValue(), 2, null); }