Refine search
BigDecimal bd = new BigDecimal("10.0001"); System.out.println(bd.toString()); // prints 10.0001 //or alternatively BigDecimal bd = nBigDecimal.valueOf(10.0001); System.out.println(bd.toString()); // prints 10.0001
protected PGBigDecimal( BigDecimal x ) { // ensure the value is a valid numeric value to avoid // sql injection attacks val = new BigDecimal(x.toString()); }
/** * 人民币金额单位转换,元转换成分,例如:1 => 100 */ public static BigDecimal yuan2fen(BigDecimal y) { if (y != null) { return yuan2fen(y.toString()); } else { return new BigDecimal(0); } }
new BigDecimal("0.06").multiply(new BigDecimal("3")).toString()
/** * Return a string in floating point format. * * @param digits The precision (number of digits) * @return The human-readable version in base 10. */ public String toFString(int digits) { if (b.compareTo(BigInteger.ONE) != 0) { MathContext mc = new MathContext(digits, RoundingMode.DOWN); BigDecimal f = (new BigDecimal(a)).divide(new BigDecimal(b), mc); return (f.toString()); } else { return a.toString(); } } /* Rational.toFString */
/** * Computes the mean in a way that is obvious and resilient to overflow by using BigInteger * arithmetic. */ private static int computeMeanSafely(int x, int y) { BigInteger bigX = BigInteger.valueOf(x); BigInteger bigY = BigInteger.valueOf(y); BigDecimal bigMean = new BigDecimal(bigX.add(bigY)).divide(BigDecimal.valueOf(2), BigDecimal.ROUND_FLOOR); // parseInt blows up on overflow as opposed to intValue() which does not. return Integer.parseInt(bigMean.toString()); }
/** * Computes the mean in a way that is obvious and resilient to overflow by using BigInteger * arithmetic. */ private static long computeMeanSafely(long x, long y) { BigInteger bigX = BigInteger.valueOf(x); BigInteger bigY = BigInteger.valueOf(y); BigDecimal bigMean = new BigDecimal(bigX.add(bigY)).divide(BigDecimal.valueOf(2), BigDecimal.ROUND_FLOOR); // parseInt blows up on overflow as opposed to intValue() which does not. return Long.parseLong(bigMean.toString()); }
/** * * 提供精确的加法运算 * * @param v1 * * @param v2 * * @return 两个参数数学加和,以字符串格式返回 */ public static String add(String v1, String v2) { try { BigDecimal b1 = new BigDecimal(v1); BigDecimal b2 = new BigDecimal(v2); return b1.add(b2).toString(); } catch (Exception e) { return "0"; } }
/** * * 提供精确的加法运算 * * @param v1 * * @param v2 * * @return 两个参数数学加和,以字符串格式返回 */ public static String add(String v1, String v2) { try { BigDecimal b1 = new BigDecimal(v1); BigDecimal b2 = new BigDecimal(v2); return b1.add(b2).toString(); } catch (Exception e) { return "0"; } }
/** * * 提供精确的减法运算 * * @param v1 * * @param v2 * * @return 两个参数数学差,以字符串格式返回 */ public static String subtract(String v1, String v2) { try { BigDecimal b1 = new BigDecimal(v1); BigDecimal b2 = new BigDecimal(v2); return b1.subtract(b2).toString(); } catch (Exception e) { return "0"; } }
/** * * 提供精确的减法运算 * * @param v1 * * @param v2 * * @return 两个参数数学差,以字符串格式返回 */ public static String subtract(String v1, String v2) { try { BigDecimal b1 = new BigDecimal(v1); BigDecimal b2 = new BigDecimal(v2); return b1.subtract(b2).toString(); } catch (Exception e) { return "0"; } }
/** * * 提供精确的乘法运算 * * @param v1 * * @param v2 * * @return 两个参数的数学积,以字符串格式返回 */ public static String multiply(String v1, String v2) { try { BigDecimal b1 = new BigDecimal(v1); BigDecimal b2 = new BigDecimal(v2); return b1.multiply(b2).toString(); } catch (Exception e) { return "0"; } }
/** * * 提供精确的乘法运算 * * @param v1 * * @param v2 * * @return 两个参数的数学积,以字符串格式返回 */ public static String multiply(String v1, String v2) { try { BigDecimal b1 = new BigDecimal(v1); BigDecimal b2 = new BigDecimal(v2); return b1.multiply(b2).toString(); } catch (Exception e) { return "0"; } }
public static String createJdoDecimalString(Decimal d) { return new BigDecimal(new BigInteger(d.getUnscaled()), d.getScale()).toString(); } }
@Override public Void visitDecimal18Constant(Decimal18Expression decExpr, StringBuilder sb) throws RuntimeException { BigDecimal value = new BigDecimal(decExpr.getLongFromDecimal()); sb.append((value.setScale(decExpr.getScale())).toString()); return null; }
@Override public Void visitDecimal9Constant(Decimal9Expression decExpr, StringBuilder sb) throws RuntimeException { BigDecimal value = new BigDecimal(decExpr.getIntFromDecimal()); sb.append((value.setScale(decExpr.getScale())).toString()); return null; }
public static String getReadableSize(long length) { if (length >= 0 && length < SIZE_BT) { // Math.round四舍五入 return (double) (Math.round(length * 10) / 10.0) + "B"; } else if (length >= SIZE_BT && length < SIZE_KB) { // //length/SIZE_BT+"KB"; return (double) (Math.round((length / SIZE_BT) * 10) / 10.0) + "KB"; } else if (length >= SIZE_KB && length < SIZE_MB) { // length/SIZE_KB+"MB"; return (double) (Math.round((length / SIZE_KB) * 10) / 10.0) + "MB"; } else if (length >= SIZE_MB && length < SIZE_GB) { // bigdecimal这个对象进行数据相互除 BigDecimal longs = new BigDecimal(Double.valueOf(length + "") .toString()); BigDecimal sizeMB = new BigDecimal(Double.valueOf(SIZE_MB + "") .toString()); String result = longs.divide(sizeMB, SACLE, BigDecimal.ROUND_HALF_UP).toString(); return result + "GB"; } else { // bigdecimal这个对象进行数据相互除 BigDecimal longs = new BigDecimal(Double.valueOf(length + "") .toString()); BigDecimal sizeMB = new BigDecimal(Double.valueOf(SIZE_GB + "") .toString()); String result = longs.divide(sizeMB, SACLE, BigDecimal.ROUND_HALF_UP).toString(); return result + "TB"; } }
BigDecimal b1 = new BigDecimal(v1); BigDecimal b2 = new BigDecimal(v2); return b1.divide(b2, scale, round_mode).toString(); } catch (Exception e) { return "0";
BigDecimal b1 = new BigDecimal(v1); BigDecimal b2 = new BigDecimal(v2); return b1.divide(b2, scale, round_mode).toString(); } catch (Exception e) { return "0";
df.setParseBigDecimal(true); BigDecimal bd = (BigDecimal) df.parseObject(numberString); System.out.println(bd.toString()); } catch (ParseException e) { e.printStackTrace(); BigDecimal bd1 = new BigDecimal(nf.parse(numberString).toString()); System.out.println(bd1.toString()); } catch (ParseException e) { e.printStackTrace(); System.out.println(new BigDecimal(numberStringFixed));; System.out.println(new BigDecimal(numberString));;