List of usage examples for java.math BigDecimal toString
@Override
public String toString()
From source file:Main.java
public static String str2Bi(String d) { BigDecimal bigDecimal = new BigDecimal(d); bigDecimal = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP); return bigDecimal.toString(); }
From source file:co.tuzza.swipehq.models.BaseRequest.java
public static void addIfhasValue(String key, BigDecimal value, Map<String, String> params) { if (value != null) { params.put(key, value.toString()); }/* w w w. jav a 2s .c om*/ }
From source file:cn.ctyun.amazonaws.util.StringUtils.java
public static String fromBigDecimal(BigDecimal value) { return value.toString(); }
From source file:com.autentia.wuija.trace.persistence.OperationalTraceBuilder.java
public static OperationalTraceParams generateParam(String paramName, Operator operator, BigDecimal param) { return generateParam(paramName, operator, param.toString()); }
From source file:org.cryptomath.util.NumberUtil.java
public static String spillFloats(String value, final int pTimes) { String result;// w w w . ja va 2 s .com if (value.matches("[\\d]*")) { BigDecimal bd = new BigDecimal(value); int f = CryptoConfigSpec.getInstance().getMathConfig().getFractions(); bd = bd.divide(new BigDecimal("10").pow(f * pTimes)); result = bd.toString(); } else { throw new NumberFormatException(MessageFormat.format("Invalid argument {0}", value)); } return result; }
From source file:it.geosolutions.geobatch.destination.common.utils.FeatureLoaderUtils.java
/** * Load all the values from a given BigDecimal attribute and return a list of String * //from w w w .java 2 s .co m * <b>The result is cached</b> * * @param datastore * @param featureTypeName * @param attribute * @param forceLoading * @return */ public static List<String> loadFeatureAttributes(DataStore datastore, String featureTypeName, String attribute, boolean forceLoading) { List<BigDecimal> list = loadFeatureAttributesInternal(datastore, featureTypeName, attribute, forceLoading); List<String> resultList = new ArrayList<String>(); for (BigDecimal el : list) { resultList.add(el.toString()); } return resultList; }
From source file:org.springframework.data.simpledb.attributeutil.AmazonSimpleDBUtil.java
public static String encodeRealNumberRange(BigDecimal number, int maxNumDigits, BigDecimal offsetValue) { final BigDecimal offsetNumber = number.add(offsetValue); final String longString = offsetNumber.toString(); final int numZeroes = maxNumDigits - longString.length(); final int paddedSize = numZeroes + longString.length(); final StringBuilder strBuffer = new StringBuilder(paddedSize); for (int i = 0; i < numZeroes; i++) { strBuffer.insert(i, '0'); }/* w ww . ja v a 2 s . c om*/ strBuffer.append(longString); return strBuffer.toString(); }
From source file:org.springframework.data.simpledb.attributeutil.AmazonSimpleDBUtil.java
public static String encodeRealNumberRange(BigDecimal number, int maxDigitsLeft, int maxDigitsRight, BigDecimal offsetValue) { BigDecimal shiftMultiplier = new BigDecimal(Math.pow(BASE, maxDigitsRight)); BigDecimal shiftedNumber = number.multiply(shiftMultiplier); shiftedNumber = shiftedNumber.setScale(0, BigDecimal.ROUND_HALF_UP); final BigDecimal shiftedOffset = offsetValue.multiply(shiftMultiplier); final BigDecimal offsetNumber = shiftedNumber.add(shiftedOffset); String longString = offsetNumber.toString(); final int numBeforeDecimal = longString.length(); final int numZeroes = maxDigitsLeft + maxDigitsRight - numBeforeDecimal; final int paddedSize = numZeroes + longString.length(); final StringBuilder strBuffer = new StringBuilder(paddedSize); for (int i = 0; i < numZeroes; i++) { strBuffer.insert(i, '0'); }/*from w w w. ja va 2 s. c om*/ strBuffer.append(longString); return strBuffer.toString(); }
From source file:nu.mine.kino.projects.ExcelScheduleBeanSheet.java
private static String date2excelSerialValue(Date date) { long time = date.getTime(); // System.out.println("longValue: " + time); BigDecimal dec = new BigDecimal(time).divide(new BigDecimal("86400000")); BigDecimal ans = dec.add(new BigDecimal("25569")).add(new BigDecimal("0.375")); // System.out.println("out: " + ans.toString()); return ans.toString(); }
From source file:com.github.sarxos.xchange.impl.FetchOpenExchangeImpl.java
private static Collection<ExchangeRate> read(String json, String to, Collection<String> from) throws JsonProcessingException, IOException { // example JSON // {/* w ww . ja v a 2s.c o m*/ // "disclaimer": "...", // "license": "...", // "timestamp": 1427716861, // "base": "USD", // "rates": { // "AED": 3.67305, // "AFN": 57.780167, // "ALL": 129.4859, // "AMD": 471.586001, // "ANG": 1.78948, // "AOA": 107.97125, // ... etc for more symbols LOG.trace("Reading JSON tree: {}", json); JsonNode root = MAPPER.readTree(json); if (root == null) { throw new IOException("Invalid JSON received: " + json); } JsonNode rates = root.get("rates"); if (rates == null) { throw new IOException("No rate element has been found in received JSON: " + json); } Iterator<Entry<String, JsonNode>> entries = rates.fields(); Map<String, BigDecimal> currencies = new HashMap<>(); while (entries.hasNext()) { Entry<String, JsonNode> entry = entries.next(); String symbol = entry.getKey(); String value = entry.getValue().asText(); currencies.put(symbol, new BigDecimal(value)); } BigDecimal base = currencies.get(to); Set<ExchangeRate> exchangerates = new HashSet<>(); for (Entry<String, BigDecimal> entry : currencies.entrySet()) { String symbol = entry.getKey(); if (!from.contains(symbol)) { continue; } BigDecimal rate = entry.getValue(); BigDecimal newrate = rate.divide(base, 8, RoundingMode.HALF_EVEN); exchangerates.add(new ExchangeRate(to + symbol, newrate.toString())); } return exchangerates; }