本文整理了Java中java.math.BigDecimal.toString()
方法的一些代码示例,展示了BigDecimal.toString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BigDecimal.toString()
方法的具体详情如下:
包路径:java.math.BigDecimal
类名称:BigDecimal
方法名:toString
[英]Returns a canonical string representation of this BigDecimal. If necessary, scientific notation is used. This representation always prints all significant digits of this value.
If the scale is negative or if scale - precision >= 6 then scientific notation is used.
[中]返回此BigDecimal的规范字符串表示形式。如有必要,使用科学符号。此表示法始终打印此值的所有有效数字。
如果刻度为负数或刻度精度>=6,则使用科学符号。
代码示例来源:origin: stackoverflow.com
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
代码示例来源:origin: postgresql/postgresql
protected PGBigDecimal( BigDecimal x )
{
// ensure the value is a valid numeric value to avoid
// sql injection attacks
val = new BigDecimal(x.toString());
}
代码示例来源:origin: vipshop/vjtools
/**
* 人民币金额单位转换,元转换成分,例如:1 => 100
*/
public static BigDecimal yuan2fen(BigDecimal y) {
if (y != null) {
return yuan2fen(y.toString());
} else {
return new BigDecimal(0);
}
}
代码示例来源:origin: stackoverflow.com
new BigDecimal("0.06").multiply(new BigDecimal("3")).toString()
代码示例来源:origin: deeplearning4j/nd4j
/**
* 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 */
代码示例来源:origin: google/guava
/**
* 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());
}
代码示例来源:origin: google/guava
/**
* 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());
}
代码示例来源:origin: G-Joker/WeaponApp
/**
*
* 提供精确的加法运算
*
* @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";
}
}
代码示例来源:origin: G-Joker/WeaponApp
/**
*
* 提供精确的加法运算
*
* @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";
}
}
代码示例来源:origin: G-Joker/WeaponApp
/**
*
* 提供精确的减法运算
*
* @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";
}
}
代码示例来源:origin: G-Joker/WeaponApp
/**
*
* 提供精确的减法运算
*
* @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";
}
}
代码示例来源:origin: G-Joker/WeaponApp
/**
*
* 提供精确的乘法运算
*
* @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";
}
}
代码示例来源:origin: G-Joker/WeaponApp
/**
*
* 提供精确的乘法运算
*
* @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";
}
}
代码示例来源:origin: apache/hive
public static String createJdoDecimalString(Decimal d) {
return new BigDecimal(new BigInteger(d.getUnscaled()), d.getScale()).toString();
}
}
代码示例来源:origin: apache/drill
@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;
}
代码示例来源:origin: apache/drill
@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;
}
代码示例来源:origin: jiangqqlmj/FastDev4Android
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";
}
}
代码示例来源:origin: G-Joker/WeaponApp
BigDecimal b1 = new BigDecimal(v1);
BigDecimal b2 = new BigDecimal(v2);
return b1.divide(b2, scale, round_mode).toString();
} catch (Exception e) {
return "0";
代码示例来源:origin: G-Joker/WeaponApp
BigDecimal b1 = new BigDecimal(v1);
BigDecimal b2 = new BigDecimal(v2);
return b1.divide(b2, scale, round_mode).toString();
} catch (Exception e) {
return "0";
代码示例来源:origin: stackoverflow.com
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));;
内容来源于网络,如有侵权,请联系作者删除!