本文整理了Java中java.math.BigDecimal.toPlainString()
方法的一些代码示例,展示了BigDecimal.toPlainString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BigDecimal.toPlainString()
方法的具体详情如下:
包路径:java.math.BigDecimal
类名称:BigDecimal
方法名:toPlainString
[英]Returns a string representation of this BigDecimal. No scientific notation is used. This methods adds zeros where necessary.
If this string representation is used to create a new instance, this instance is generally not identical to this as the precision changes.
x.equals(new BigDecimal(x.toPlainString()) usually returns false.
x.compareTo(new BigDecimal(x.toPlainString()) returns 0.
[中]返回此BigDecimal的字符串表示形式。没有使用科学符号。此方法在必要时添加零。
如果此字符串表示用于创建新实例,则随着精度的变化,此实例通常与此实例不同。
x、 equals(新的BigDecimal(x.toPlainString())通常返回false。
x、 compareTo(新的BigDecimal(x.toPlainString())返回0。
代码示例来源:origin: jenkinsci/jenkins
/**
* Gets GB left.
*/
public String getGbLeft() {
long space = size;
space/=1024L; // convert to KB
space/=1024L; // convert to MB
return new BigDecimal(space).scaleByPowerOfTen(-3).toPlainString();
}
代码示例来源:origin: redisson/redisson
@Override
public Double zIncrBy(byte[] key, double increment, byte[] value) {
return write(key, DoubleCodec.INSTANCE, RedisCommands.ZINCRBY,
key, new BigDecimal(increment).toPlainString(), value);
}
代码示例来源:origin: redisson/redisson
@Override
public Double zIncrBy(byte[] key, double increment, byte[] value) {
return write(key, DoubleCodec.INSTANCE, RedisCommands.ZINCRBY,
key, new BigDecimal(increment).toPlainString(), value);
}
代码示例来源:origin: redisson/redisson
@Override
public Double zIncrBy(byte[] key, double increment, byte[] value) {
return write(key, DoubleCodec.INSTANCE, RedisCommands.ZINCRBY,
key, new BigDecimal(increment).toPlainString(), value);
}
代码示例来源:origin: redisson/redisson
@Override
public Double zIncrBy(byte[] key, double increment, byte[] value) {
return write(key, DoubleCodec.INSTANCE, RedisCommands.ZINCRBY,
key, new BigDecimal(increment).toPlainString(), value);
}
代码示例来源:origin: stackoverflow.com
@FacesConverter("bigDecimalPlainDisplay")
public class BigDecimalDisplayConverter implements Converter {
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
throw new BigDecimal(value);
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
BigDecimal bd = (BigDecimal)value;
return bd.setScale(2, RoundingMode.HALF_UP).stripTrailingZeros().toPlainString();
}
}
代码示例来源:origin: stackoverflow.com
static Double round(Double d, int precise)
{
BigDecimal bigDecimal = new BigDecimal(d);
System.out.println("Before round: " + bigDecimal.toPlainString());
bigDecimal = bigDecimal.setScale(15, RoundingMode.HALF_UP);
System.out.println("Hack round: " + bigDecimal.toPlainString());
bigDecimal = bigDecimal.setScale(precise, RoundingMode.HALF_UP);
System.out.println("After round: " + bigDecimal.toPlainString());
return bigDecimal.doubleValue();
}
代码示例来源:origin: AdoptOpenJDK/jitwatch
private String millisToSecondsString(long millis)
{
return new BigDecimal(Long.toString(millis)).divide(new BigDecimal("1000")).toPlainString();
}
代码示例来源:origin: AdoptOpenJDK/jitwatch
private String millisToSecondsString(long millis)
{
return new BigDecimal(Long.toString(millis)).divide(new BigDecimal("1000")).toPlainString();
}
代码示例来源:origin: apache/kylin
public static String normalizeNumber(String v) {
boolean badBegin = (v.startsWith("0") && v.length() > 1 && v.charAt(1) != '.') //
|| (v.startsWith("-0") && v.length() > 2 && v.charAt(2) != '.') //
|| v.startsWith("+");
if (badBegin) {
v = new BigDecimal(v).toPlainString();
}
while (v.contains(".") && (v.endsWith("0") || v.endsWith("."))) {
v = v.substring(0, v.length() - 1);
}
return v;
}
代码示例来源:origin: alibaba/easyexcel
public static String formatFloat0(String value, int n) {
if (null != value && value.contains(".")) {
if (isNumeric(value)) {
try {
BigDecimal decimal = new BigDecimal(value);
BigDecimal setScale = decimal.setScale(n, BigDecimal.ROUND_HALF_DOWN);
return setScale.toPlainString();
} catch (Exception e) {
}
}
}
return value;
}
代码示例来源:origin: alibaba/easyexcel
public static String formatFloat(String value) {
if (null != value && value.contains(".")) {
if (isNumeric(value)) {
try {
BigDecimal decimal = new BigDecimal(value);
BigDecimal setScale = decimal.setScale(10, BigDecimal.ROUND_HALF_DOWN).stripTrailingZeros();
return setScale.toPlainString();
} catch (Exception e) {
}
}
}
return value;
}
代码示例来源:origin: stackoverflow.com
import java.math.BigDecimal;
import java.text.DecimalFormat;
public class Runner {
public static void main(String[] args) {
double myvalue = 0.00000021d;
//Option 1 Print bare double.
System.out.println(myvalue);
//Option2, use decimalFormat.
DecimalFormat df = new DecimalFormat("#");
df.setMaximumFractionDigits(8);
System.out.println(df.format(myvalue));
//Option 3, use printf.
System.out.printf("%.9f", myvalue);
System.out.println();
//Option 4, convert toBigDecimal and ask for toPlainString().
System.out.println(new BigDecimal(myvalue).toPlainString());
System.out.println();
//Option 5, String.format
System.out.println(String.format("%.12f", myvalue));
}
}
代码示例来源:origin: stackoverflow.com
BigDecimal d = new BigDecimal("600.0").setScale(2, RoundingMode.HALF_UP).stripTrailingZeros();
System.out.println(d.toPlainString()); // Printed 600 for me
代码示例来源:origin: smuyyh/BookReader
public static String getFormatSize(double size) {
double kiloByte = size / 1024;
if (kiloByte < 1) {
return "0K";
}
double megaByte = kiloByte / 1024;
if (megaByte < 1) {
BigDecimal result1 = new BigDecimal(Double.toString(kiloByte));
return result1.setScale(2, BigDecimal.ROUND_HALF_UP)
.toPlainString() + "KB";
}
double gigaByte = megaByte / 1024;
if (gigaByte < 1) {
BigDecimal result2 = new BigDecimal(Double.toString(megaByte));
return result2.setScale(2, BigDecimal.ROUND_HALF_UP)
.toPlainString() + "MB";
}
double teraBytes = gigaByte / 1024;
if (teraBytes < 1) {
BigDecimal result3 = new BigDecimal(Double.toString(gigaByte));
return result3.setScale(2, BigDecimal.ROUND_HALF_UP)
.toPlainString() + "GB";
}
BigDecimal result4 = new BigDecimal(teraBytes);
return result4.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString()
+ "TB";
}
代码示例来源:origin: stackoverflow.com
public static void main (String[] args) throws java.lang.Exception
{
System.out.println("Rounded: " + round(2.655d,2)); // -> 2.65
System.out.println("Rounded: " + round(1.655d,2)); // -> 1.66
}
public static Double round(Double d, int precise)
{
BigDecimal bigDecimal = new BigDecimal(d);
System.out.println("Before round: " + bigDecimal.toPlainString());
bigDecimal = bigDecimal.setScale(precise, RoundingMode.HALF_UP);
System.out.println("After round: " + bigDecimal.toPlainString());
return bigDecimal.doubleValue();
}
代码示例来源:origin: redisson/redisson
@Override
public RFuture<Integer> addScoreAndGetRankAsync(V object, Number value) {
return commandExecutor.evalWriteAsync(getName(), LongCodec.INSTANCE, RedisCommands.EVAL_INTEGER,
"redis.call('zincrby', KEYS[1], ARGV[1], ARGV[2]); "
+"return redis.call('zrank', KEYS[1], ARGV[2]); ",
Collections.<Object>singletonList(getName()), new BigDecimal(value.toString()).toPlainString(), encode(object));
}
代码示例来源:origin: redisson/redisson
@Override
public RFuture<Integer> addScoreAndGetRevRankAsync(V object, Number value) {
return commandExecutor.evalWriteAsync(getName(), LongCodec.INSTANCE, RedisCommands.EVAL_INTEGER,
"redis.call('zincrby', KEYS[1], ARGV[1], ARGV[2]); "
+"return redis.call('zrevrank', KEYS[1], ARGV[2]); ",
Collections.<Object>singletonList(getName()), new BigDecimal(value.toString()).toPlainString(), encode(object));
}
代码示例来源:origin: redisson/redisson
@Override
public RFuture<Integer> addScoreAndGetRankAsync(V object, Number value) {
return commandExecutor.evalWriteAsync(getName(), LongCodec.INSTANCE, RedisCommands.EVAL_INTEGER,
"redis.call('zincrby', KEYS[1], ARGV[1], ARGV[2]); "
+"return redis.call('zrank', KEYS[1], ARGV[2]); ",
Collections.<Object>singletonList(getName()), new BigDecimal(value.toString()).toPlainString(), encode(object));
}
代码示例来源:origin: redisson/redisson
@Override
public RFuture<Integer> addScoreAndGetRevRankAsync(V object, Number value) {
return commandExecutor.evalWriteAsync(getName(), LongCodec.INSTANCE, RedisCommands.EVAL_INTEGER,
"redis.call('zincrby', KEYS[1], ARGV[1], ARGV[2]); "
+"return redis.call('zrevrank', KEYS[1], ARGV[2]); ",
Collections.<Object>singletonList(getName()), new BigDecimal(value.toString()).toPlainString(), encode(object));
}
内容来源于网络,如有侵权,请联系作者删除!