Tabnine Logo
BigDecimal.<init>
Code IndexAdd Tabnine to your IDE (free)

How to use
java.math.BigDecimal
constructor

Best Java code snippets using java.math.BigDecimal.<init> (Showing top 20 results out of 32,499)

Refine searchRefine arrow

  • PrintStream.println
  • BigDecimal.setScale
  • Test.<init>
  • BigDecimal.divide
  • BigInteger.<init>
  • Assert.assertEquals
  • BigDecimal.doubleValue
  • BigDecimal.multiply
  • BigDecimal.add
  • Assert.assertThat
origin: clojure/clojure

public BigDecimal decimalValue(MathContext mc){
  BigDecimal numerator = new BigDecimal(this.numerator);
  BigDecimal denominator = new BigDecimal(this.denominator);

  return numerator.divide(denominator, mc);
}

origin: stackoverflow.com

 System.out.println(new BigDecimal(1.03).subtract(new BigDecimal(0.41)));
System.out.println(new BigDecimal("1.03").subtract(new BigDecimal("0.41")));
origin: stackoverflow.com

new BigDecimal(value).setScale(places, RoundingMode.HALF_UP).doubleValue()
origin: spring-projects/spring-framework

@Test
public void parseBigDecimalNumber1() {
  String bigDecimalAsString = "0.10";
  Number bigDecimal = NumberUtils.parseNumber(bigDecimalAsString, BigDecimal.class);
  assertEquals(new BigDecimal(bigDecimalAsString), bigDecimal);
}
origin: stackoverflow.com

 BigDecimal _0_1 = new BigDecimal(0.1);
BigDecimal x = _0_1;
for(int i = 1; i <= 10; i ++) {
  System.out.println(i+" x 0.1 is "+x+", as double "+x.doubleValue());
  x = x.add(_0_1);
}
origin: stackoverflow.com

 public static void main(String[] args) {
 String doubleVal = "1.745";
 String doubleVal1 = "0.745";
 BigDecimal bdTest = new BigDecimal(  doubleVal);
 BigDecimal bdTest1 = new BigDecimal(  doubleVal1 );
 bdTest = bdTest.setScale(2, BigDecimal.ROUND_HALF_UP);
 bdTest1 = bdTest1.setScale(2, BigDecimal.ROUND_HALF_UP);
 System.out.println("bdTest:"+bdTest); //1.75
 System.out.println("bdTest1:"+bdTest1);//0.75, no problem
}
origin: stackoverflow.com

 double r = 5.1234;
System.out.println(r); // r is 5.1234

int decimalPlaces = 2;
BigDecimal bd = new BigDecimal(r);

// setScale is immutable
bd = bd.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP);
r = bd.doubleValue();

System.out.println(r); // r is 5.12
origin: apache/drill

@Test
public void test_getObject_handles_DECIMAL_2() throws SQLException {
 assertThat( testDataRow.getObject( "C_DECIMAL_10.10" ),
       equalTo( (Object) new BigDecimal( "10.10" ) ) );
}
origin: spring-projects/spring-framework

@Test
public void convertBigDecimalToBigInteger() {
  String number = "987459837583750387355346";
  BigDecimal decimal = new BigDecimal(number);
  assertEquals(new BigInteger(number), NumberUtils.convertNumberToTargetClass(decimal, BigInteger.class));
}
origin: stackoverflow.com

 BigDecimal test = new BigDecimal(0);
System.out.println(test);
test = test.add(new BigDecimal(30));
System.out.println(test);
test = test.add(new BigDecimal(45));
System.out.println(test);
origin: spring-projects/spring-framework

@Test
public void setNumberPropertiesWithCoercion() {
  NumberTestBean target = new NumberTestBean();
    accessor.setPropertyValue("short2", new Integer(2));
    accessor.setPropertyValue("int2", new Long(8));
    accessor.setPropertyValue("long2", new BigInteger("6"));
    accessor.setPropertyValue("bigInteger", new Integer(3));
    accessor.setPropertyValue("float2", new Double(8.1));
    accessor.setPropertyValue("double2", new BigDecimal(6.1));
    accessor.setPropertyValue("bigDecimal", new Float(4.0));
  assertTrue("Correct long2 value", new Long("6").equals(accessor.getPropertyValue("long2")));
  assertTrue("Correct long2 value", new Long("6").equals(target.getLong2()));
  assertTrue("Correct bigInteger value", new BigInteger("3").equals(accessor.getPropertyValue("bigInteger")));
  assertTrue("Correct bigInteger value", new BigInteger("3").equals(target.getBigInteger()));
  assertTrue("Correct float2 value", new Float("8.1").equals(accessor.getPropertyValue("float2")));
  assertTrue("Correct float2 value", new Float("8.1").equals(target.getFloat2()));
  assertTrue("Correct double2 value", new Double("6.1").equals(accessor.getPropertyValue("double2")));
  assertTrue("Correct double2 value", new Double("6.1").equals(target.getDouble2()));
  assertTrue("Correct bigDecimal value", new BigDecimal("4.0").equals(accessor.getPropertyValue("bigDecimal")));
  assertTrue("Correct bigDecimal value", new BigDecimal("4.0").equals(target.getBigDecimal()));
origin: knowm/XChange

public BigDecimal calculateFeeBtc() {
 return roundUp(amount.multiply(new BigDecimal(.5))).divide(new BigDecimal(100.));
}
origin: stackoverflow.com

 public static double round(double value, int places) {
  if (places < 0) throw new IllegalArgumentException();

  BigDecimal bd = new BigDecimal(value);
  bd = bd.setScale(places, RoundingMode.HALF_UP);
  return bd.doubleValue();
}
origin: stackoverflow.com

 public static BigDecimal sqrt(BigDecimal A, final int SCALE) {
  BigDecimal x0 = new BigDecimal("0");
  BigDecimal x1 = new BigDecimal(Math.sqrt(A.doubleValue()));
  while (!x0.equals(x1)) {
    x0 = x1;
    x1 = A.divide(x0, SCALE, ROUND_HALF_UP);
    x1 = x1.add(x0);
    x1 = x1.divide(TWO, SCALE, ROUND_HALF_UP);

  }
  return x1;
}
origin: prestodb/presto

public static Optional<BigDecimal> fromMetastoreDecimal(@Nullable Decimal decimal)
{
  if (decimal == null) {
    return Optional.empty();
  }
  return Optional.of(new BigDecimal(new BigInteger(decimal.getUnscaled()), decimal.getScale()));
}
origin: knowm/XChange

public BigDecimal getAveragePrice() {
 return low.add(high).divide(new BigDecimal("2"));
}
origin: BroadleafCommerce/BroadleafCommerce

  public BigDecimal getHitRate() {
    if (getRequestCount() == 0) {
      return new BigDecimal(-1);
    }
    BigDecimal percentage = new BigDecimal(getCacheHitCount()).divide(new BigDecimal(getRequestCount
        ()), 2, BigDecimal.ROUND_HALF_UP);
    percentage = percentage.multiply(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
    return percentage;
  }
}
origin: spring-projects/spring-framework

@Test
public void parseBigDecimalNumber2() {
  String bigDecimalAsString = "0.001";
  Number bigDecimal = NumberUtils.parseNumber(bigDecimalAsString, BigDecimal.class);
  assertEquals(new BigDecimal(bigDecimalAsString), bigDecimal);
}
origin: knowm/XChange

System.out.println("fetching data...");
System.out.println("orderBook = " + orderBook);
System.out.println("received data.");
System.out.println("plotting...");
BigDecimal accumulatedBidUnits = new BigDecimal("0");
for (LimitOrder limitOrder : orderBook.getBids()) {
 if (limitOrder.getLimitPrice().doubleValue() > 5000) {
  xData.add(limitOrder.getLimitPrice());
  accumulatedBidUnits = accumulatedBidUnits.add(limitOrder.getOriginalAmount());
  yData.add(accumulatedBidUnits);
BigDecimal accumulatedAskUnits = new BigDecimal("0");
for (LimitOrder limitOrder : orderBook.getAsks()) {
 if (limitOrder.getLimitPrice().doubleValue() < 20000) {
  xData.add(limitOrder.getLimitPrice());
  accumulatedAskUnits = accumulatedAskUnits.add(limitOrder.getOriginalAmount());
  yData.add(accumulatedAskUnits);
origin: stackoverflow.com

 System.out.println(new BigDecimal(0.1));
System.out.println(new BigDecimal(x));
java.mathBigDecimal<init>

Javadoc

Constructs a new BigDecimal instance from the 64bit double val. The constructed big decimal is equivalent to the given double. For example, new BigDecimal(0.1) is equal to 0.1000000000000000055511151231257827021181583404541015625. This happens as 0.1 cannot be represented exactly in binary.

To generate a big decimal instance which is equivalent to 0.1 use the BigDecimal(String) constructor.

Popular methods of BigDecimal

  • valueOf
  • compareTo
    Compares this BigDecimal with the specified BigDecimal. Two BigDecimal objects that are equal in val
  • doubleValue
    Converts this BigDecimal to a double. This conversion is similar to thenarrowing primitive conversio
  • setScale
    Returns a BigDecimal whose scale is the specified value, and whose unscaled value is determined by m
  • divide
  • add
  • multiply
  • toString
    Returns the string representation of this BigDecimal, using scientific notation if an exponent is ne
  • subtract
    Returns a BigDecimal whose value is (this - subtrahend), with rounding according to the context sett
  • intValue
    Converts this BigDecimal to an int. This conversion is analogous to thenarrowing primitive conversio
  • longValue
    Converts this BigDecimal to a long. This conversion is analogous to thenarrowing primitive conversio
  • toPlainString
    Returns a string representation of this BigDecimalwithout an exponent field. For values with a posit
  • longValue,
  • toPlainString,
  • scale,
  • toBigInteger,
  • equals,
  • floatValue,
  • negate,
  • unscaledValue,
  • abs

Popular in Java

  • Finding current android device location
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • onRequestPermissionsResult (Fragment)
  • setRequestProperty (URLConnection)
  • FlowLayout (java.awt)
    A flow layout arranges components in a left-to-right flow, much like lines of text in a paragraph. F
  • Kernel (java.awt.image)
  • URLConnection (java.net)
    A connection to a URL for reading or writing. For HTTP connections, see HttpURLConnection for docume
  • HashMap (java.util)
    HashMap is an implementation of Map. All optional operations are supported.All elements are permitte
  • Semaphore (java.util.concurrent)
    A counting semaphore. Conceptually, a semaphore maintains a set of permits. Each #acquire blocks if
  • JComboBox (javax.swing)
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now