List of usage examples for java.math BigDecimal ZERO
BigDecimal ZERO
To view the source code for java.math BigDecimal ZERO.
Click Source Link
From source file:com.benfante.minimark.blo.ResultCalculationBo.java
/** * Evaluate an assessment normalizing the sum of the marks of each question * to a maximum value.//from ww w . j a v a 2s .c om * * @param assessment The assessment to evaluate. * @param maxValue The maximum value to wich normalize. If it's null, the default is 100. * @return The evaluation */ public BigDecimal calculateNormalizedSum(AssessmentFilling assessment, BigDecimal maxValue) { if (maxValue == null) { maxValue = new BigDecimal("100.00"); } BigDecimal result = new BigDecimal("0.00"); for (QuestionFilling questionFilling : assessment.getQuestions()) { result = addQuestionMarkedWeight(questionFilling, result); } final BigDecimal totalWeight = assessment.getTotalWeight(); if (!BigDecimal.ZERO.equals(totalWeight)) { result = result.multiply(maxValue).divide(totalWeight, 2, RoundingMode.HALF_EVEN); } return result; }
From source file:org.jrecruiter.service.JobServiceTest.java
private Job getJob() { Job job = new Job(); job.setBusinessAddress1("businessAddress1"); job.setBusinessAddress2("businessAddress2"); job.setBusinessCity("businessCity"); job.setBusinessEmail("businessEmail"); job.setRegionOther("businessLocation"); job.setBusinessName("businessName"); job.setBusinessPhone("businessPhone"); job.setBusinessState("businessState"); job.setBusinessZip("businessZip"); job.setDescription("description"); job.setJobRestrictions("jobRestrictions"); job.setJobTitle("jobTitle"); job.setLatitude(BigDecimal.ONE); job.setLongitude(BigDecimal.ZERO); job.setOfferedBy(OfferedBy.RECRUITER); job.setRegistrationDate(new Date()); job.setSalary("10000"); job.setStatus(JobStatus.ACTIVE); job.setUpdateDate(new Date()); job.setWebsite("www.google.com"); return job;//from w ww . j a v a2 s . com }
From source file:org.parancoe.plugin.configuration.PropertyDaoTest.java
@Test public void findRealProperty() { Category category = categoryDao.findByName("second_category"); Property property = propertyDao.findByNameAndCategoryId("real_property", category.getId()); assertThat(property.getType(), equalTo(PropertyType.REAL)); assertThat(property.getValueAsReal(), closeTo(new BigDecimal("3.141592653589793238462643383279502884197169399375105820974944592"), BigDecimal.ZERO)); }
From source file:com.wms.utils.DataUtil.java
/** * Kiem tra Bigdecimal bi null hoac zero * * @param value/*from w w w . j a v a2 s. c o m*/ * @return */ public static boolean isNullOrZero(BigDecimal value) { return (value == null || value.equals(BigDecimal.ZERO)); }
From source file:edu.byu.softwareDistribution.web.controller.shopper.ShoppingCartController.java
@RequestMapping(value = "/shop/shoppingCart.htm") public String displayPage(Model model, @RequestParam(value = "byuId", required = false) String byuId) { final List<LineItem> items = new ArrayList<LineItem>(cart.getItems()); final BigDecimal total = cart.getTotalPrice(); final List<LineItemDisplayHelper> displayItems = cart.getItemsWithKeys(); final Map<Integer, Boolean> returnable = new HashMap<Integer, Boolean>(); model.addAttribute("items", displayItems); for (final LineItemDisplayHelper lineItem : displayItems) { if (lineItem.getValue().getType() == LineItem.Type.MAINTENANCE_LINE_ITEM) { returnable.put(lineItem.getKey(), true); continue; }/*from w w w . ja va 2s . com*/ final PurchaseLineItem pli = (PurchaseLineItem) lineItem.getValue(); returnable.put(lineItem.getKey(), licenseManager.isReturnable(pli.getProduct().getProductId())); } model.addAttribute("productReturnable", returnable); model.addAttribute("totalPrice", total); model.addAttribute("personRepo", personRepo); model.addAttribute("needsAccountCode", BigDecimal.ZERO.compareTo(total) != 0); model.addAttribute("itemCount", items.size()); model.addAttribute("cart", cart); model.addAttribute("maintType", LineItem.Type.MAINTENANCE_LINE_ITEM); final IdentityDetails currentIdentityDetails = IdentityDetails.getCurrentIdentityDetails(); String personId = ""; if (byuId != null) { personId = basicPersonLookup.getPersonByByuId(byuId).getPersonId(); } else { personId = currentIdentityDetails.getPersonId(); } LOG.debug("Identity Details id: " + personId); model.addAttribute("accountCodes", purchaseManager.getUsedAccountCodes(personId)); model.addAttribute("signedInName", currentIdentityDetails.getName()); LOG.info("Total Price: " + total); return "shop/shoppingCart"; }
From source file:com.nearinfinity.honeycomb.hbase.bulkload.FieldParser.java
private static ByteBuffer extractDecimal(String val, int precision, int right_scale) { int left_scale = precision - 2; BigDecimal x = new BigDecimal(val); boolean is_negative = x.compareTo(BigDecimal.ZERO) == -1; x = x.abs();/*from w w w. j a va 2 s . co m*/ BigDecimal left = x.setScale(0, RoundingMode.DOWN); BigDecimal right = x.subtract(left).movePointRight(right_scale); int right_bytes_len = bytesFromDigits(right_scale); int left_bytes_len = bytesFromDigits(left_scale); byte[] left_bytes = left.toBigInteger().toByteArray(); byte[] right_bytes = right.toBigInteger().toByteArray(); // Bit twiddling is fun byte[] buff = new byte[left_bytes_len + right_bytes_len]; System.arraycopy(left_bytes, 0, buff, left_bytes_len - left_bytes.length, left_bytes.length); System.arraycopy(right_bytes, 0, buff, right_bytes_len - right_bytes.length + left_bytes_len, right_bytes.length); buff[0] ^= -128; // Flip first bit, 0x80 if (is_negative) { // Flip all bits for (int i = 0; i < buff.length; i++) { buff[i] ^= -1; // 0xff } } return ByteBuffer.wrap(buff); }
From source file:engine.Pi.java
/** * Compute the value, in radians, of the arctangent of * the inverse of the supplied integer to the specified * number of digits after the decimal point. The value * is computed using the power series expansion for the * arc tangent:// w w w. j a va2 s . co m * * arctan(x) = x - (x^3)/3 + (x^5)/5 - (x^7)/7 + * (x^9)/9 ... */ public static BigDecimal arctan(int inverseX, int scale) { BigDecimal result, numer, term; BigDecimal invX = BigDecimal.valueOf(inverseX); BigDecimal invX2 = BigDecimal.valueOf(inverseX * inverseX); numer = BigDecimal.ONE.divide(invX, scale, roundingMode); result = numer; int i = 1; do { numer = numer.divide(invX2, scale, roundingMode); int denom = 2 * i + 1; term = numer.divide(BigDecimal.valueOf(denom), scale, roundingMode); if ((i % 2) != 0) { result = result.subtract(term); } else { result = result.add(term); } i++; } while (term.compareTo(BigDecimal.ZERO) != 0); return result; }
From source file:net.groupbuy.controller.admin.SalesController.java
/** * /*from w w w. j av a 2 s . co m*/ */ @RequestMapping(value = "/view", method = RequestMethod.GET) public String view(Type type, Date beginDate, Date endDate, Model model) { if (type == null) { type = Type.month; } if (beginDate == null) { beginDate = DateUtils.addMonths(new Date(), -11); } if (endDate == null) { endDate = new Date(); } Map<Date, BigDecimal> salesAmountMap = new LinkedHashMap<Date, BigDecimal>(); Map<Date, Integer> salesVolumeMap = new LinkedHashMap<Date, Integer>(); Calendar beginCalendar = DateUtils.toCalendar(beginDate); Calendar endCalendar = DateUtils.toCalendar(endDate); int beginYear = beginCalendar.get(Calendar.YEAR); int endYear = endCalendar.get(Calendar.YEAR); int beginMonth = beginCalendar.get(Calendar.MONTH); int endMonth = endCalendar.get(Calendar.MONTH); for (int year = beginYear; year <= endYear; year++) { if (salesAmountMap.size() >= MAX_SIZE) { break; } Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, year); if (type == Type.year) { calendar.set(Calendar.MONTH, calendar.getActualMinimum(Calendar.MONTH)); calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DATE)); calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMinimum(Calendar.HOUR_OF_DAY)); calendar.set(Calendar.MINUTE, calendar.getActualMinimum(Calendar.MINUTE)); calendar.set(Calendar.SECOND, calendar.getActualMinimum(Calendar.SECOND)); Date begin = calendar.getTime(); calendar.set(Calendar.MONTH, calendar.getActualMaximum(Calendar.MONTH)); calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE)); calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMaximum(Calendar.HOUR_OF_DAY)); calendar.set(Calendar.MINUTE, calendar.getActualMaximum(Calendar.MINUTE)); calendar.set(Calendar.SECOND, calendar.getActualMaximum(Calendar.SECOND)); Date end = calendar.getTime(); BigDecimal salesAmount = orderService.getSalesAmount(begin, end); Integer salesVolume = orderService.getSalesVolume(begin, end); salesAmountMap.put(begin, salesAmount != null ? salesAmount : BigDecimal.ZERO); salesVolumeMap.put(begin, salesVolume != null ? salesVolume : 0); } else { for (int month = year == beginYear ? beginMonth : calendar.getActualMinimum(Calendar.MONTH); month <= (year == endYear ? endMonth : calendar.getActualMaximum(Calendar.MONTH)); month++) { if (salesAmountMap.size() >= MAX_SIZE) { break; } calendar.set(Calendar.MONTH, month); calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DATE)); calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMinimum(Calendar.HOUR_OF_DAY)); calendar.set(Calendar.MINUTE, calendar.getActualMinimum(Calendar.MINUTE)); calendar.set(Calendar.SECOND, calendar.getActualMinimum(Calendar.SECOND)); Date begin = calendar.getTime(); calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE)); calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMaximum(Calendar.HOUR_OF_DAY)); calendar.set(Calendar.MINUTE, calendar.getActualMaximum(Calendar.MINUTE)); calendar.set(Calendar.SECOND, calendar.getActualMaximum(Calendar.SECOND)); Date end = calendar.getTime(); BigDecimal salesAmount = orderService.getSalesAmount(begin, end); Integer salesVolume = orderService.getSalesVolume(begin, end); salesAmountMap.put(begin, salesAmount != null ? salesAmount : BigDecimal.ZERO); salesVolumeMap.put(begin, salesVolume != null ? salesVolume : 0); } } } model.addAttribute("types", Type.values()); model.addAttribute("type", type); model.addAttribute("beginDate", beginDate); model.addAttribute("endDate", endDate); model.addAttribute("salesAmountMap", salesAmountMap); model.addAttribute("salesVolumeMap", salesVolumeMap); return "/admin/sales/view"; }
From source file:net.sf.reportengine.util.TestCalculatorIntermResultMatrix.java
/** * Test method for {@link net.sf.reportengine.util.CalculatorIntermResultsMatrix#initRow(int)}. *//*from w ww. j av a 2s .c o m*/ @Test public final void testInitRow() { classUnderTest = new CalculatorIntermResultsMatrix(1, TEST_DATA_COLUMNS); //call the method under test classUnderTest.initRow(0); //check the interm results matrix Assert.assertNotNull(classUnderTest); Assert.assertNotNull(classUnderTest.getIntermResultsMatrix()); Assert.assertEquals(classUnderTest.getIntermResultsMatrix().length, 1); //the first row should be re-initialized CalcIntermResult[] row1 = classUnderTest.getIntermResultsMatrix()[0]; Assert.assertNotNull(row1); Assert.assertEquals(row1.length, 2); Assert.assertEquals(row1[0].getResult(), NumberUtils.INTEGER_ZERO); Assert.assertEquals(row1[1].getResult(), BigDecimal.ZERO); }
From source file:cn.bjfu.springdao.jpa.domain.order.Order.java
/** * Returns the total of the {@link Order}. * //from w w w .j a va2s .c o m * @return */ public BigDecimal getTotal() { BigDecimal total = BigDecimal.ZERO; for (LineItem item : lineItems) { total = total.add(item.getTotal()); } return total; }