List of utility methods to do BigDecimal
BigDecimal | safeToBigDecimal(Object obj1) safe To Big Decimal BigDecimal result = BigDecimal.ZERO; if (obj1 == null) { return result; try { result = new BigDecimal(obj1.toString()); } catch (Exception ex) { return result; |
Vector | scalarMult(BigDecimal scalar, Vector scalar Mult Vector<BigDecimal> c = (Vector<BigDecimal>) a.clone(); for (int i = 0; i < a.size(); i++) c.set(i, scalar.multiply(((BigDecimal) a.get(i)))); return c; |
BigDecimal | scale(BigDecimal b1, BigDecimal b2) scale return b1.divide(b2, 5).multiply(BigDecimal.valueOf(100));
|
BigDecimal | scale2(BigDecimal valor) Retorna valor com scale = 2 e RoundingMode.FLOOR if (null != valor) return valor.setScale(2, RoundingMode.FLOOR); else return valor; |
BigDecimal | scaleCurrency(BigDecimal amount) scale Currency return amount.setScale(2, BigDecimal.ROUND_HALF_UP);
|
BigDecimal | secondsBigDecimalFromDuration(long s, int n) seconds Big Decimal From Duration if (n == 0) return BigDecimal.valueOf(s); int scale = 9; boolean huge = (int) s != s; long ns = huge ? n : s * 1000000000L + n; while (ns % 10 == 0) { ns = ns / 10; scale--; ... |
int | signum(final BigDecimal value) If value is null return 0 otherwise the signum(). return value == null ? 0 : value.signum();
|
BigDecimal | sine(BigDecimal x) sine BigDecimal lastVal = x.add(BigDecimal.ONE); BigDecimal currentValue = x; BigDecimal xSquared = x.multiply(x); BigDecimal numerator = x; BigDecimal denominator = BigDecimal.ONE; int i = 0; while (lastVal.compareTo(currentValue) != 0) { lastVal = currentValue; ... |
Map | sortByValues(Map sort By Values List sortedByValueList = new LinkedList(map.entrySet()); Collections.sort(sortedByValueList, new Comparator<Map.Entry<String, BigDecimal>>() { public int compare(Entry<String, BigDecimal> o1, Entry<String, BigDecimal> o2) { return ((Comparable) (o2).getValue()).compareTo((o1).getValue()); }); Map<String, BigDecimal> sortedHashMap = new LinkedHashMap<String, BigDecimal>(); for (Iterator it = sortedByValueList.iterator(); it.hasNext();) { ... |
Map | sortMapByBDValue(Map sort Map By BD Value Map<T, BigDecimal> sortedMap = new LinkedHashMap<T, BigDecimal>(); if (oriMap != null && !oriMap.isEmpty()) { List<Map.Entry<T, BigDecimal>> entryList = new ArrayList<Map.Entry<T, BigDecimal>>(oriMap.entrySet()); Collections.sort(entryList, new Comparator<Map.Entry<T, BigDecimal>>() { public int compare(Entry<T, BigDecimal> entry1, Entry<T, BigDecimal> entry2) { BigDecimal value1 = entry1.getValue(); BigDecimal value2 = entry2.getValue(); return value2.compareTo(value1); ... |