List of usage examples for org.apache.commons.math.util MathUtils round
public static float round(float x, int scale)
From source file:org.sakaiproject.tool.assessment.ui.bean.evaluation.QuestionScoresBean.java
/** * get the max score * * @return the max score */ public double getMaxScore() { return MathUtils.round(maxScore, 2); }
From source file:org.skfiy.typhon.spi.pvp.PvpProvider.java
private void giveHighRankAward(Normal normal) { int lastRanking; if (normal.getPvpHighRanking() <= 0) { lastRanking = maxPvpHigestRanking; } else {/* w w w . ja va2 s. com*/ lastRanking = normal.getPvpHighRanking() - 1; } // ????? if (normal.getPvpRanking() > lastRanking || normal.getPvpRanking() > maxPvpHigestRanking) { return; } // int diamond = 0; int i = pvpHighestRanks.size() - 1; PvpHighestRank highestRank; for (;;) { highestRank = pvpHighestRanks.get(i); // ?? if (highestRank.beginRanking <= lastRanking && highestRank.endRanking >= lastRanking) { if (normal.getPvpRanking() >= highestRank.beginRanking) { diamond += (lastRanking - normal.getPvpRanking() + 1) * highestRank.count; lastRanking = normal.getPvpRanking(); } else { diamond += (lastRanking - highestRank.beginRanking + 1) * highestRank.count; lastRanking = highestRank.beginRanking - 1; } } // ??????? if (i <= 0 || normal.getPvpRanking() > highestRank.endRanking) { break; } i--; } if (diamond > 100) { diamond = (int) MathUtils.round(diamond / 100D, 0); } else { diamond = 1; } // ?? Mail mail = new Mail(); mail.setTitle("??"); mail.setContent(String.format("%1d??????%2d??", normal.getPvpRanking(), normal.getPvpHighRanking() - normal.getPvpRanking())); mail.setAppendix(Typhons.getProperty("typhon.spi.singleDiamondItemId")); mail.setCount(diamond); mail.setType(Mail.REWARD_NOTICE_TYPE); roleProvider.sendMail(normal.player().getRole().getRid(), mail); // ?? normal.setPvpHighRanking(normal.getPvpRanking()); }
From source file:org.skfiy.typhon.spi.war.WarProvider.java
/** * * @param we/*from w ww.j a v a 2s. c o m*/ * @return */ public WarReport.Entity newWarReportEntity(WarInfo.Entity we) { WarReport.Entity rs = new WarReport.Entity(); rs.setRoleName(we.getRoleName()); rs.setLevel(we.getLevel()); rs.setPowerGuess(we.getPowerGuess()); rs.setSuccorIid(we.getSuccor().getHeroId()); // FIXME Test rs.setSuccorAtk(we.getSuccor().getAtk()); rs.setSuccorFury(we.getSuccor().getFury()); List<JSONObject> heros = new ArrayList<>(we.getFightObjects().size()); for (FightObject fo : we.getFightObjects()) { JSONObject json = new JSONObject(); json.put(HeroPropertyKeys.ID, fo.getHeroId()); json.put(HeroPropertyKeys.LADDER, fo.getLadder()); json.put(HeroPropertyKeys.STAR, fo.getStar()); json.put(HeroPropertyKeys.LEVEL, fo.getLevel()); json.put(HeroPropertyKeys.HP, fo.getMaxHp()); json.put(HeroPropertyKeys.FURY, fo.getFury()); // FIXME Test Data json.put(HeroPropertyKeys.ATK, fo.getAtk()); json.put(HeroPropertyKeys.DEF, fo.getDef()); json.put(HeroPropertyKeys.MATK, fo.getMatk()); json.put(HeroPropertyKeys.MDEF, fo.getMdef()); json.put(HeroPropertyKeys.CRIT_RATE, MathUtils.round(fo.getCritRate(), 3)); json.put(HeroPropertyKeys.DECRIT_RATE, MathUtils.round(fo.getDecritRate(), 3)); json.put(HeroPropertyKeys.CRIT_MAGN, MathUtils.round(fo.getCritMagn(), 3)); json.put(HeroPropertyKeys.PARRY_RATE, MathUtils.round(fo.getParryRate(), 3)); json.put(HeroPropertyKeys.DEPARRY_RATE, MathUtils.round(fo.getDeparryRate(), 3)); json.put(HeroPropertyKeys.PARRY_VALUE, MathUtils.round(fo.getParryValue(), 3)); heros.add(json); } rs.setHeros(heros); return rs; }
From source file:org.vincibean.salestaxes.service.converter.PoiuytConverter.java
@Override public org.vincibean.salestaxes.generated.Poiuyt convert(org.vincibean.salestaxes.domain.Poiuyt source) { org.vincibean.salestaxes.generated.Poiuyt target = new org.vincibean.salestaxes.generated.Poiuyt(); target.setName(source.getName());/* w ww .j a va2 s. c o m*/ target.setDescription(source.getDescription()); for (org.vincibean.salestaxes.domain.Category category : source.getCategorySet()) { target.getCategory().add(categoryConverter.convert(category)); } target.setBasePrice(source.getPrice()); // Round the final price for avoiding inaccuracies due to floating point numbers limitations(discrete mathematics) target.setFinalPrice(MathUtils.round( source.getPrice() + Rounder.round(PoiuytPriceCalculator.calculateTotalTaxesPerPoiuyt(source)), 2)); return target; }
From source file:org.vincibean.salestaxes.service.ReceiptServiceTest.java
/** * Test that, given Input://from ww w.j a va 2 s . c om * - 1 book at 12.49, * - 1 music CD at 14.99, * - 1 chocolate bar at 0.85 * the Output will be: * - 1 book at 12.49, * - 1 music CD at 16.49, * - 1 chocolate bar at 0.85 * Sales Taxes: 1.50 * Total: 29.83 */ @Test public void testGenerateReceipt1() { // Names list final String BOOK_NAME = "Book"; final String MUSIC_CD_NAME = "Music CD"; final String CHOCOLATE_BAR_NAME = "Chocolate Bar"; // Prices list final double BOOK_PRICE = 12.49; final double MUSIC_CD_PRICE = 14.99; final double CHOCOLATE_BAR_PRICE = 0.85; // Create a book Poiuyt. Poiuyt book = new Poiuyt(); book.setName(BOOK_NAME); book.setDescription(BOOK_NAME); book.setPrice(BOOK_PRICE); book.setCategorySet(Sets.newHashSet(createNoTaxesCategory())); // Create a music CD Poiuyt. Poiuyt musicCd = new Poiuyt(); musicCd.setName(MUSIC_CD_NAME); musicCd.setDescription(MUSIC_CD_NAME); musicCd.setPrice(MUSIC_CD_PRICE); musicCd.setCategorySet(Sets.newHashSet(createSalesTaxesCategory())); // Create a chocolate bar Poiuyt. Poiuyt chocolateBar = new Poiuyt(); chocolateBar.setName(CHOCOLATE_BAR_NAME); chocolateBar.setDescription(CHOCOLATE_BAR_NAME); chocolateBar.setPrice(CHOCOLATE_BAR_PRICE); chocolateBar.setCategorySet(Sets.newHashSet(createNoTaxesCategory())); // Generate a Receipt with the above Poiuyts. Receipt receipt = receiptService.generateReceipt(Lists.newArrayList(book, musicCd, chocolateBar)); boolean priceTestResult = true; for (org.vincibean.salestaxes.generated.Poiuyt poiuyt : receipt.getPoiuyts()) { // Every Poiuyt belong to just 1 category switch (poiuyt.getName()) { case BOOK_NAME: priceTestResult = priceTestResult && new Double(BOOK_PRICE).equals(MathUtils.round(poiuyt.getFinalPrice(), 2)); break; case MUSIC_CD_NAME: priceTestResult = priceTestResult && new Double(16.49).equals(poiuyt.getFinalPrice()); break; case CHOCOLATE_BAR_NAME: priceTestResult = priceTestResult && new Double(CHOCOLATE_BAR_PRICE).equals(poiuyt.getFinalPrice()); break; default: fail("Unexpected Poiuyt found"); break; } } assertTrue(priceTestResult); assertEquals(1.50, receipt.getTotalTaxes(), 0.01); assertEquals(29.83, receipt.getGrandTotal(), 0.01); }
From source file:tuwien.dbai.wpps.embrowser.addons.DOMSelectionBox.java
private void positionDiv(double x, double y, double width, double height) { double mainWidth = width; double mainHeight = height; //adjust for borders (DIVS) width -= config.borderWidth;//from www . j a v a 2 s . c om height -= config.borderWidth; //check for negative values /* if( x<0 ) x=0; if( y<0 ) y=0; */ if (width < 0) width = 0; if (height < 0) height = 0; String xStr = Double.toString(MathUtils.round(x, 2)); String yStr = Double.toString(MathUtils.round(y, 2)); String mainWidthStr = Double.toString(MathUtils.round(mainWidth, 2)); String mainHeightStr = Double.toString(MathUtils.round(mainHeight, 2)); String widthStr = Double.toString(MathUtils.round(width, 2)); String heightStr = Double.toString(MathUtils.round(height, 2)); mainDivStyleDecl.setProperty("left", xStr + "px", "important"); mainDivStyleDecl.setProperty("top", yStr + "px", "important"); if (config.coverAreaSelected) { mainDivStyleDecl.setProperty("width", mainWidthStr + "px", ""); mainDivStyleDecl.setProperty("height", mainHeightStr + "px", ""); } //bounds northDivStyleDecl.setProperty("width", widthStr + "px", ""); //dynamic eastDivStyleDecl.setProperty("left", widthStr + "px", ""); //dynamic eastDivStyleDecl.setProperty("height", heightStr + "px", ""); //dynamic southDivStyleDecl.setProperty("top", heightStr + "px", ""); //dynamic southDivStyleDecl.setProperty("width", widthStr + "px", ""); //dynamic westDivStyleDecl.setProperty("height", heightStr + "px", ""); //dynamic }
From source file:uk.ac.ebi.atlas.profiles.baseline.BaselineExpressionLevelRounder.java
public double round(double value) { int numberOfFractionalDigits = 0; if (value >= 1) numberOfFractionalDigits = FRACTIONAL_DIGITS_FOR_VALUE_LARGER_OR_EQUAL_TO_ONE; else if (value >= 0.1) numberOfFractionalDigits = FRACTIONAL_DIGITS_FOR_VALUE_SMALLER_THAN_ONE; else// ww w .ja v a 2 s.c om numberOfFractionalDigits = FRACTIONAL_DIGITS_FOR_VALUE_SMALLER_THAN_ZEROPOINTONE; return MathUtils.round(value, numberOfFractionalDigits); }
From source file:uk.ac.ebi.atlas.profiles.differential.viewmodel.FoldChangeRounder.java
public double round(double number) { return MathUtils.round(number, 1); }
From source file:uk.ac.ebi.spot.rdf.model.utils.NumberUtils.java
public double round(double number, int maxFractionDigits) { return MathUtils.round(number, maxFractionDigits); }