public BigDecimal convert (@Nonnull final Object aSource) { return StringParser.parseBigDecimal (aSource.toString (), (BigDecimal) null); } });
/** * Parse the given {@link String} as {@link BigDecimal}. * * @param sStr * The String to parse. May be <code>null</code>. * @return <code>null</code> if the string does not represent a valid value. */ @Nullable public static BigDecimal parseBigDecimal (@Nullable final String sStr) { return parseBigDecimal (sStr, null); }
/** * Parse the given {@link String} as {@link BigDecimal}. * * @param sStr * The String to parse. May be <code>null</code>. * @param nScale * The scaling (decimal places) to be used for the result. Must be ≥ * 0! * @param eRoundingMode * The rounding mode to be used to achieve the scale. May not be * <code>null</code>. * @return <code>null</code> if the string does not represent a valid value. */ @Nullable public static BigDecimal parseBigDecimal (@Nullable final String sStr, @Nonnegative final int nScale, @Nonnull final RoundingMode eRoundingMode) { return parseBigDecimal (sStr, nScale, eRoundingMode, null); }
/** * Get the matching Java version from a class version. * * @param nMajor * Major version number * @param nMinor * Minor version number * @return {@link #UNKNOWN} if the version could not be determined. */ @Nonnull public static EJavaVersion getFromMajorAndMinor (final int nMajor, final int nMinor) { final double dVersion = StringParser.parseBigDecimal (nMajor + "." + nMinor).doubleValue (); return getFromVersionNumber (dVersion); }
@Nullable public static CSSSimpleValueWithUnit getValueWithUnit (@Nullable final String sCSSValue, final boolean bWithPerc) { String sRealValue = StringHelper.trim (sCSSValue); if (StringHelper.hasText (sRealValue)) { // Special case for 0! if (sRealValue.equals ("0")) return new CSSSimpleValueWithUnit (BigDecimal.ZERO, ECSSUnit.PX); final ECSSUnit eUnit = bWithPerc ? getMatchingUnitInclPercentage (sRealValue) : getMatchingUnitExclPercentage (sRealValue); if (eUnit != null) { // Cut the unit off sRealValue = sRealValue.substring (0, sRealValue.length () - eUnit.getName ().length ()).trim (); final BigDecimal aValue = StringParser.parseBigDecimal (sRealValue); if (aValue != null) return new CSSSimpleValueWithUnit (aValue, eUnit); } } return null; } }
@Nullable public static CSSSimpleValueWithUnit getValueWithUnit (@Nullable final String sCSSValue, final boolean bWithPerc) { String sRealValue = StringHelper.trim (sCSSValue); if (StringHelper.hasText (sRealValue)) { // Special case for 0! if (sRealValue.equals ("0")) return new CSSSimpleValueWithUnit (BigDecimal.ZERO, ECSSUnit.PX); final ECSSUnit eUnit = bWithPerc ? getMatchingUnitInclPercentage (sRealValue) : getMatchingUnitExclPercentage (sRealValue); if (eUnit != null) { // Cut the unit off sRealValue = sRealValue.substring (0, sRealValue.length () - eUnit.getName ().length ()).trim (); final BigDecimal aValue = StringParser.parseBigDecimal (sRealValue); if (aValue != null) return new CSSSimpleValueWithUnit (aValue, eUnit); } } return null; } }
final BigDecimal aPercentage = StringParser.parseBigDecimal (sPercentage, null); if (aPercentage == null)