org.apache.calcite.util.Util.toScientificNotation()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(4.2k)|赞(0)|评价(0)|浏览(106)

本文整理了Java中org.apache.calcite.util.Util.toScientificNotation()方法的一些代码示例,展示了Util.toScientificNotation()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.toScientificNotation()方法的具体详情如下:
包路径:org.apache.calcite.util.Util
类名称:Util
方法名:toScientificNotation

Util.toScientificNotation介绍

[英]Formats a BigDecimal value to a string in scientific notation For example

  • A value of 0.00001234 would be formated as 1.234E-5
  • A value of 100000.00 would be formated as 1.00E5
  • A value of 100 (scale zero) would be formated as 1E2

If bd has a precision higher than 20, this method will truncate the output string to have a precision of 20 (no rounding will be done, just a truncate).
[中]例如,将BigDecimal值格式化为科学记数法中的字符串
*0.00001234的值将被格式化为1.234E-5
*100000.00的值将被格式化为1.00E5
*100(零标度)的值将被格式化为1E2
如果bd的精度高于20,此方法将截断输出字符串,使其精度达到20(不进行舍入,只进行截断)。

代码示例

代码示例来源:origin: apache/flink

private void validateLiteralAsDouble(SqlLiteral literal) {
  BigDecimal bd = (BigDecimal) literal.getValue();
  double d = bd.doubleValue();
  if (Double.isInfinite(d) || Double.isNaN(d)) {
    // overflow
    throw newValidationError(literal,
      RESOURCE.numberLiteralOutOfRange(Util.toScientificNotation(bd)));
  }
  // REVIEW jvs 4-Aug-2004:  what about underflow?
}

代码示例来源:origin: org.apache.calcite/calcite-core

public String toValue() {
 BigDecimal bd = (BigDecimal) value;
 if (isExact) {
  return value.toString();
 }
 return Util.toScientificNotation(bd);
}

代码示例来源:origin: Qihoo360/Quicksql

public String toValue() {
 BigDecimal bd = (BigDecimal) value;
 if (isExact) {
  return value.toString();
 }
 return Util.toScientificNotation(bd);
}

代码示例来源:origin: org.apache.calcite/calcite-core

private void validateLiteralAsDouble(SqlLiteral literal) {
 BigDecimal bd = (BigDecimal) literal.getValue();
 double d = bd.doubleValue();
 if (Double.isInfinite(d) || Double.isNaN(d)) {
  // overflow
  throw newValidationError(literal,
    RESOURCE.numberLiteralOutOfRange(Util.toScientificNotation(bd)));
 }
 // REVIEW jvs 4-Aug-2004:  what about underflow?
}

代码示例来源:origin: Qihoo360/Quicksql

private void validateLiteralAsDouble(SqlLiteral literal) {
 BigDecimal bd = (BigDecimal) literal.getValue();
 double d = bd.doubleValue();
 if (Double.isInfinite(d) || Double.isNaN(d)) {
  // overflow
  throw newValidationError(literal,
    RESOURCE.numberLiteralOutOfRange(Util.toScientificNotation(bd)));
 }
 // REVIEW jvs 4-Aug-2004:  what about underflow?
}

代码示例来源:origin: Qihoo360/Quicksql

case DOUBLE:
 assert value instanceof BigDecimal;
 pw.print(Util.toScientificNotation((BigDecimal) value));
 break;
case BIGINT:

代码示例来源:origin: org.apache.calcite/calcite-core

case DOUBLE:
 assert value instanceof BigDecimal;
 pw.print(Util.toScientificNotation((BigDecimal) value));
 break;
case BIGINT:

代码示例来源:origin: Qihoo360/Quicksql

TestUtil.assertEqualsVerbose(
  "1.234E-3",
  Util.toScientificNotation(bd));
bd = new BigDecimal("0.001");
TestUtil.assertEqualsVerbose(
  "1E-3",
  Util.toScientificNotation(bd));
bd = new BigDecimal("-0.001");
TestUtil.assertEqualsVerbose(
  "-1E-3",
  Util.toScientificNotation(bd));
bd = new BigDecimal("1");
TestUtil.assertEqualsVerbose(
  "1E0",
  Util.toScientificNotation(bd));
bd = new BigDecimal("-1");
TestUtil.assertEqualsVerbose(
  "-1E0",
  Util.toScientificNotation(bd));
bd = new BigDecimal("1.0");
TestUtil.assertEqualsVerbose(
  "1.0E0",
  Util.toScientificNotation(bd));
bd = new BigDecimal("12345");
TestUtil.assertEqualsVerbose(
  "1.2345E4",
  Util.toScientificNotation(bd));
bd = new BigDecimal("12345.00");
TestUtil.assertEqualsVerbose(

代码示例来源:origin: org.apache.calcite/calcite-core

TestUtil.assertEqualsVerbose(
  "1.234E-3",
  Util.toScientificNotation(bd));
bd = new BigDecimal("0.001");
TestUtil.assertEqualsVerbose(
  "1E-3",
  Util.toScientificNotation(bd));
bd = new BigDecimal("-0.001");
TestUtil.assertEqualsVerbose(
  "-1E-3",
  Util.toScientificNotation(bd));
bd = new BigDecimal("1");
TestUtil.assertEqualsVerbose(
  "1E0",
  Util.toScientificNotation(bd));
bd = new BigDecimal("-1");
TestUtil.assertEqualsVerbose(
  "-1E0",
  Util.toScientificNotation(bd));
bd = new BigDecimal("1.0");
TestUtil.assertEqualsVerbose(
  "1.0E0",
  Util.toScientificNotation(bd));
bd = new BigDecimal("12345");
TestUtil.assertEqualsVerbose(
  "1.2345E4",
  Util.toScientificNotation(bd));
bd = new BigDecimal("12345.00");
TestUtil.assertEqualsVerbose(

相关文章