本文整理了Java中java.math.BigDecimal.toEngineeringString()
方法的一些代码示例,展示了BigDecimal.toEngineeringString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BigDecimal.toEngineeringString()
方法的具体详情如下:
包路径:java.math.BigDecimal
类名称:BigDecimal
方法名:toEngineeringString
[英]Returns a string representation of this BigDecimal. This representation always prints all significant digits of this value.
If the scale is negative or if scale - precision >= 6 then engineering notation is used. Engineering notation is similar to the scientific notation except that the exponent is made to be a multiple of 3 such that the integer part is >= 1 and < 1000.
[中]返回此BigDecimal的字符串表示形式。此表示法始终打印此值的所有有效数字。
如果标度为负值或标度-精度>=6,则使用工程符号。工程表示法与科学表示法类似,不同之处在于指数是3的倍数,因此整数部分大于等于1且小于1000。
代码示例来源:origin: zendesk/maxwell
@Override
public String toSQL(Object value) {
BigDecimal d = (BigDecimal) value;
return d.toEngineeringString();
}
}
代码示例来源:origin: stackoverflow.com
BigDecimal bigDecimal = BigDecimal.valueOf(100000.0)
.multiply(BigDecimal.valueOf(100d))
.stripTrailingZeros();
System.out.println("plain : " + bigDecimal.toPlainString());
System.out.println("scientific : " + bigDecimal.toEngineeringString());
代码示例来源:origin: UniversaBlockchain/universa
public String toEngineeringString() {
return value.toEngineeringString();
}
代码示例来源:origin: stackoverflow.com
public static String formatDecimal(BigDecimal b, int max) {
return b.setScale(max, RoundingMode.HALF_EVEN).stripTrailingZeros().toEngineeringString();
}
代码示例来源:origin: stackoverflow.com
BigDecimal val1=new BigDecimal(97346822*3f);
BigDecimal val2=new BigDecimal(97346822*3.0);
System.out.println(val1.subtract(val2, MathContext.UNLIMITED).toEngineeringString());
System.out.println(val1.equals(val2));
System.out.println(val1.compareTo(val2));
代码示例来源:origin: stackoverflow.com
BigDecimal bd = new BigDecimal("8678679532108467840356746356832624562456786656736.6456442652456345673656");
int decimalOffset = 0;
if (bd.toPlainString().indexOf('.')>=0)
decimalOffset=1;
System.out.println(bd.toPlainString().length()-decimalOffset<32 ? bd.toPlainString() : bd.toEngineeringString());
代码示例来源:origin: org.hjson/hjson
@Override
public String toString() {
long l=(long)value;
if (l==value) return Long.toString(l);
String res=BigDecimal.valueOf(value).toEngineeringString();
if (res.endsWith(".0")) return res.substring(0, res.length()-2);
else if (res.contains("E")) {
res=Double.toString(value);
res=res.replace("E-", "e-").replace("E", "e+");
}
return res;
}
代码示例来源:origin: stackoverflow.com
BigDecimal val1=new BigDecimal(3.1f);
BigDecimal val2=new BigDecimal(3.1);
System.out.println(val1.subtract(val2, MathContext.UNLIMITED).toEngineeringString()); //-95.367431729442841970012523233890533447265625E-9
System.out.println(val1.equals(val2)); //false
System.out.println(val1.compareTo(val2)); // -1
System.out.println(val1.precision()); // 22
System.out.println(val2.precision()); // 52
代码示例来源:origin: hjson/hjson-java
@Override
public String toString() {
long l=(long)value;
if (l==value) return Long.toString(l);
String res=BigDecimal.valueOf(value).toEngineeringString();
if (res.endsWith(".0")) return res.substring(0, res.length()-2);
else if (res.contains("E")) {
res=Double.toString(value);
res=res.replace("E-", "e-").replace("E", "e+");
}
return res;
}
代码示例来源:origin: net.razorvine/serpent
protected void serialize_bigdecimal(BigDecimal decimal, StringWriter sw, int level)
{
serialize_string(decimal.toEngineeringString(), sw, level);
}
代码示例来源:origin: stackoverflow.com
public class ExampleWithoutGenericSingletonFactory {
static UnaryFunction<Object> ID_FUNC = new UnaryFunction<Object>() {
public Object apply(Object arg) {
return arg;
}
};
public static void main(String[] args) {
BigDecimal b = new BigDecimal("1234.1241234");
BigDecimal b1 = (BigDecimal)(ID_FUNC.apply(b)); // have to cast here >_<
System.out.println("engineeringstring val of b1 = "
+ b1.toEngineeringString());
}
}
代码示例来源:origin: xap/xap
public void writeDecimal(BigDecimal value) {
String rawValue = value.toEngineeringString();
writeString(rawValue);
}
代码示例来源:origin: stackoverflow.com
BigDecimal i = new BigDecimal(0.025);
int n = 2;
BigDecimal h1 = new BigDecimal(2000);
BigDecimal h2 = new BigDecimal(4000);
BigDecimal y1 = ((BigDecimal.ONE.add(i)).pow(n)).multiply(h1);
BigDecimal y2 = ((BigDecimal.ONE.add(i)).pow(n)).multiply(h2);
BigDecimal result = y1.add(y2);
System.out.println(result.toEngineeringString());
代码示例来源:origin: net.razorvine/pyrolite
void put_decimal(BigDecimal d) throws IOException {
//"cdecimal\nDecimal\nU\n12345.6789\u0085R."
out.write(Opcodes.GLOBAL);
out.write("decimal\nDecimal\n".getBytes());
put_string(d.toEngineeringString());
out.write(Opcodes.TUPLE1);
out.write(Opcodes.REDUCE);
writeMemo(d);
}
代码示例来源:origin: org.spark-project/pyrolite
void put_decimal(BigDecimal d) throws IOException {
//"cdecimal\nDecimal\nU\n12345.6789\u0085R."
out.write(Opcodes.GLOBAL);
out.write("decimal\nDecimal\n".getBytes());
put_string(d.toEngineeringString());
out.write(Opcodes.TUPLE1);
out.write(Opcodes.REDUCE);
writeMemo(d);
}
代码示例来源:origin: net.sf.mbus4j/mbus4j-core
@Override
protected void accumulateDatatoJSON(JSONObject json) {
json.accumulate("data", getValue().toEngineeringString());
}
代码示例来源:origin: com.facebook.presto.cassandra/cassandra-driver
public final void putLongDouble(final BigDecimal value) {
byte[] ld = new byte[Type.LONGDOUBLE.size()];
Foreign.getInstance().longDoubleFromString(value.toEngineeringString(), ld, 0, Type.LONGDOUBLE.size());
getObjectBuffer().putArray(paramIndex, ld, 0, ld.length, ObjectBuffer.IN);
paramOffset += PARAM_SIZE;
++paramIndex;
}
代码示例来源:origin: io.prestosql.cassandra/cassandra-driver
public final void putLongDouble(final BigDecimal value) {
byte[] ld = new byte[Type.LONGDOUBLE.size()];
Foreign.getInstance().longDoubleFromString(value.toEngineeringString(), ld, 0, Type.LONGDOUBLE.size());
getObjectBuffer().putArray(paramIndex, ld, 0, ld.length, ObjectBuffer.IN);
paramOffset += PARAM_SIZE;
++paramIndex;
}
代码示例来源:origin: com.cloudbees.util/jnr-unixsocket-nodep
public final void putLongDouble(final BigDecimal value) {
byte[] ld = new byte[Type.LONGDOUBLE.size()];
Foreign.getInstance().longDoubleFromString(value.toEngineeringString(), ld, 0, Type.LONGDOUBLE.size());
getObjectBuffer().putArray(paramIndex, ld, 0, ld.length, ObjectBuffer.IN);
paramOffset += PARAM_SIZE;
++paramIndex;
}
代码示例来源:origin: RoboZonky/robozonky
@Test
void ipmt() {
final BigDecimal rate = new BigDecimal("0.1");
final BigDecimal principal = BigDecimal.valueOf(100);
final int maxTerm = 10;
assertSoftly(softly -> {
softly.assertThat(FinancialUtil.ipmt(rate, 1, maxTerm, principal).toEngineeringString())
.isEqualTo(BigDecimal.TEN.negate().toEngineeringString());
softly.assertThat(FinancialUtil.ipmt(rate, maxTerm, maxTerm, principal)).isLessThan(BigDecimal.ZERO);
});
}
内容来源于网络,如有侵权,请联系作者删除!