本文整理汇总了Java中java.math.BigDecimal.toString方法的典型用法代码示例。如果您正苦于以下问题:Java BigDecimal.toString方法的具体用法?Java BigDecimal.toString怎么用?Java BigDecimal.toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.math.BigDecimal
的用法示例。
在下文中一共展示了BigDecimal.toString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: format
import java.math.BigDecimal; //导入方法依赖的package包/类
public String format(BigDecimal number) {
try {
// TODO : what amount of significant digits need to be supported here?
// - from the DecimalFormat docs:
// [significant digits] = [minimum integer digits] + [maximum fraction digits]
DecimalFormat jdkFormatter = new DecimalFormat( FORMAT_STRING );
jdkFormatter.setMinimumIntegerDigits( 1 );
jdkFormatter.setMaximumFractionDigits( Integer.MAX_VALUE );
return jdkFormatter.format( number );
}
catch (Throwable t) {
throw new HibernateException(
"Unable to format decimal literal in approximate format [" + number.toString() + "]",
t
);
}
}
示例2: consistentToString
import java.math.BigDecimal; //导入方法依赖的package包/类
/**
* Takes care of the fact that Sun changed the output of
* BigDecimal.toString() between JDK-1.4 and JDK 5
*
* @param decimal
* the big decimal to stringify
*
* @return a string representation of 'decimal'
*/
public static String consistentToString(BigDecimal decimal) {
if (decimal == null) {
return null;
}
if (toPlainStringMethod != null) {
try {
return (String) toPlainStringMethod.invoke(decimal, (Object[]) null);
} catch (InvocationTargetException invokeEx) {
// that's okay, we fall-through to decimal.toString()
} catch (IllegalAccessException accessEx) {
// that's okay, we fall-through to decimal.toString()
}
}
return decimal.toString();
}
示例3: getValue
import java.math.BigDecimal; //导入方法依赖的package包/类
/**
* 判断data的类型,尝试解析成日期类型(返回{@link Date}),其次布尔类型(返回{@link Boolean}),
* 然后数字类型(转变成字符串输出),
* 前三种均解析失败则直接返回字符串data
*
* @param data
* @return 解析后的值
*/
private Object getValue(String data) {
Object value = null;
try {
//判断是否是日期类型
Date date = DateUtils.parseDate(data, DATE_PATTERN);
value = date;
} catch (ParseException e) {
//抛异常证明非日期类型
if ("true".equalsIgnoreCase(data)) {
value = Boolean.TRUE;
} else if ("false".equalsIgnoreCase(data)) {
value = Boolean.FALSE;
} else {
//判断是否数字
try {
double dbl = Double.parseDouble(data);
if (this.scale == null || this.scale <= 0) {
//不四舍五入,直接输出
value = data;
} else {
BigDecimal bd = new BigDecimal(dbl);
value = bd.toString().contains(".") ? bd.setScale(this.scale, RoundingMode.HALF_UP).toString() :
bd.toString();
}
} catch (NumberFormatException e1) {
//证明不是数字,直接输出
value = data;
}
}
}
return value;
}
示例4: keep2Decimal
import java.math.BigDecimal; //导入方法依赖的package包/类
public static String keep2Decimal(String string) {
if (null != string && !"".equals(string)) {
//构造以字符串内容为值的BigDecimal类型的变量bd
BigDecimal bd = new BigDecimal(string);
//设置小数位数,第一个变量是小数位数,第二个变量是取舍方法(四舍五入)
bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
return bd.toString();
}
return "";
}
示例5: Constant
import java.math.BigDecimal; //导入方法依赖的package包/类
/**
* Constructs a new real constant from a given (non-{@code null}) {@link BigDecimal} value.
*/
Constant(BigDecimal value) {
super(true);
this.signature = Sort.REAL;
this.symbol = value.toString();
this.realRepr = value;
this.boolRepr = null;
this.intRepr = null;
this.stringRepr = null;
}
示例6: valStr
import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
public String valStr() {
BigDecimal nr = valReal();
if (nullValue)
return null;
return nr.toString();
}
示例7: write
import java.math.BigDecimal; //导入方法依赖的package包/类
public void write(VarBufferPos buffer, BigDecimal bigDecimal)
{
String cs = bigDecimal.toString();
if(!m_bJustifyRight)
internalWriteRightPaddingSpace(buffer, cs);
else
internalWriteJustifyRightPaddingSpace(buffer, cs);
}
示例8: write
import java.math.BigDecimal; //导入方法依赖的package包/类
public void write(VarBufferPos buffer, BigDecimal bigDecimal)
{
String csDec = bigDecimal.toString();
//Pic9Comp3BufferSupport.setDec(buffer, m_nNbDigitInteger, m_nNbDigitDecimal, m_nTotalSize, 0, true, csDec);
Dec dec = NumberParserDec.getAsDec(bigDecimal);
Pic9Comp3BufferSupport.setDec(buffer, m_nNbDigitInteger, m_nNbDigitDecimal, m_nTotalSize, 0, true, dec);
}
示例9: decodeToNumeric
import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
protected String decodeToNumeric(String data, int fieldType, int precision) {
byte[] value = Base64.decodeBase64(data);
BigDecimal bigDecimal = new BigDecimal(new BigInteger(value), precision);
return bigDecimal.toString();
}
示例10: getCellValue
import java.math.BigDecimal; //导入方法依赖的package包/类
/**
* 获取指定单元格的内容。只能是日期(返回java.util.Date),整数值(返回的均是String类型),小数值(返回的均是String类型,并
* 保留两位小数),字符串, 布尔类型。 其他类型返回null。
*
* @param type 指定类型(Cell中定义的类型)
* @param cell 指定单元格
* @return 返回Cell里的内容
*/
public static Object getCellValue(int type, Cell cell) {
switch (type) {
case Cell.CELL_TYPE_BOOLEAN:
return cell.getBooleanCellValue();
case Cell.CELL_TYPE_NUMERIC:
if (DateUtil.isCellDateFormatted(cell)) {
return DateUtil.getJavaDate(cell.getNumericCellValue());
} else {
BigDecimal bd = new BigDecimal(cell.getNumericCellValue());
return bd.toString().contains(".") ? bd.setScale(2, RoundingMode.HALF_UP).toString() :
bd.toString();
}
case Cell.CELL_TYPE_STRING:
try {
return DateUtils.parseDate(cell.getStringCellValue(), ReadExcelUtils.pattern);
} catch (Exception e) {
return cell.getStringCellValue();
}
case Cell.CELL_TYPE_FORMULA:
if (DateUtil.isCellDateFormatted(cell)) {
return cell.getDateCellValue();
}
break;
default:
break;
}
return null;
}
示例11: testItem_0070
import java.math.BigDecimal; //导入方法依赖的package包/类
public void testItem_0070()
{
for (int i = 0; i < 10000; i++)
{
BigDecimal alpha = new BigDecimal("12500").setScale(3);
BigDecimal beta = new BigDecimal("1000");
beta = beta.add(alpha).setScale(0, BigDecimal.ROUND_DOWN);
String betaString = beta.toString();
Assert.assertEquals("13500", betaString);
}
}
示例12: toEscapedString
import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
protected String toEscapedString(BigDecimal value) {
return value.toString();
}
示例13: valStringFromReal
import java.math.BigDecimal; //导入方法依赖的package包/类
protected String valStringFromReal() {
BigDecimal nr = valReal();
if (nullValue)
return null; /* purecov: inspected */
return nr.toString();
}
示例14: doubleFormat
import java.math.BigDecimal; //导入方法依赖的package包/类
public static String doubleFormat(String value) {
BigDecimal bd = new BigDecimal(Double.parseDouble(value));
bd = bd.setScale(2, RoundingMode.HALF_UP);
return bd.toString();
}
示例15: ethToUsd
import java.math.BigDecimal; //导入方法依赖的package包/类
public static String ethToUsd(String priceUsd, String ethBalance) {
BigDecimal usd = new BigDecimal(ethBalance).multiply(new BigDecimal(priceUsd));
usd = usd.setScale(2, RoundingMode.CEILING);
return usd.toString();
}