List of usage examples for java.math RoundingMode FLOOR
RoundingMode FLOOR
To view the source code for java.math RoundingMode FLOOR.
Click Source Link
From source file:carrental.beans.billing.BillingBean.java
private static BigDecimal calculateDrivingCosts(long daysUsed, Car car) { return new BigDecimal(daysUsed * car.getPricePerDay()).setScale(2, RoundingMode.FLOOR); }
From source file:com.eu.evaluation.server.eva.EvaluateExcutorTest.java
@Test public void test() { double d = 0.987; logger.info("String.format = " + String.format("%.2f", d)); DecimalFormat df = new DecimalFormat("*.00"); logger.info("DecimalFormat = " + df.format(d)); NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMaximumFractionDigits(2);/*w w w . j a v a 2 s. c o m*/ logger.info("NumberFormat = " + nf.format(d)); DecimalFormat formater = new DecimalFormat(); formater.setMaximumFractionDigits(2); formater.setGroupingSize(0); formater.setRoundingMode(RoundingMode.FLOOR); logger.info("DecimalFormat = " + (formater.format(d))); }
From source file:com.streamsets.pipeline.stage.it.AllSdcTypesIT.java
@Parameterized.Parameters(name = "type({0})") public static Collection<Object[]> data() throws Exception { return Arrays.asList(new Object[][] { { Field.create(Field.Type.BOOLEAN, true), true, Types.BOOLEAN, true }, { Field.create(Field.Type.CHAR, 'A'), true, Types.VARCHAR, "A" }, { Field.create(Field.Type.BYTE, (byte) 0x00), false, 0, null }, { Field.create(Field.Type.SHORT, 10), true, Types.INTEGER, 10 }, { Field.create(Field.Type.INTEGER, 10), true, Types.INTEGER, 10 }, { Field.create(Field.Type.LONG, 10), true, Types.BIGINT, 10L }, { Field.create(Field.Type.FLOAT, 1.5), true, Types.FLOAT, 1.5 }, { Field.create(Field.Type.DOUBLE, 1.5), true, Types.DOUBLE, 1.5 }, { Field.create(Field.Type.DATE, new Date(116, 5, 13)), true, Types.DATE, new Date(116, 5, 13) }, { Field.create(Field.Type.DATETIME, date), true, Types.VARCHAR, datetimeFormat.format(date) }, { Field.create(Field.Type.TIME, date), true, Types.VARCHAR, timeFormat.format(date) }, { Field.create(Field.Type.DECIMAL, BigDecimal.valueOf(1.5)), true, Types.DECIMAL, new BigDecimal(BigInteger.valueOf(15), 1, new MathContext(2, RoundingMode.FLOOR)) }, { Field.create(Field.Type.STRING, "StreamSets"), true, Types.VARCHAR, "StreamSets" }, { Field.create(Field.Type.BYTE_ARRAY, new byte[] { (byte) 0x00 }), true, Types.BINARY, new byte[] { (byte) 0x00 } }, { Field.create(Field.Type.MAP, Collections.emptyMap()), false, 0, null }, { Field.create(Field.Type.LIST, Collections.emptyList()), false, 0, null }, { Field.create(Field.Type.LIST_MAP, new LinkedHashMap<>()), false, 0, null }, }); }
From source file:com.github.rinde.rinsim.pdptw.common.WrappedGraphUITest.java
/** * Tests that {@link GraphRoadModelRenderer} can render a * {@link PDPGraphRoadModel}.//from ww w . j a va 2 s .com */ @Test public void test() { final Graph<LengthData> g = new TableGraph<>(); Graphs.addBiPath(g, N, NE, E, SE, S, SW, W, NW, N); Graphs.addBiPath(g, N, C, S); Graphs.addBiPath(g, NE, C, SW); Graphs.addBiPath(g, NW, C, SE); Graphs.addBiPath(g, E, C, W); final Scenario.Builder b = Scenario.builder() .addModel(PDPGraphRoadModel.builderForGraphRm(RoadModelBuilders.staticGraph(g))) .addModel(DefaultPDPModel.builder()).addEvents(Collections.nCopies(10, AddVehicleEvent.create(-1, VehicleDTO.builder().startPosition(C).build()))); final int endTime = 3 * 60 * 60 * 1000; final RandomGenerator rng = new MersenneTwister(123); for (int i = 0; i < 20; i++) { final long announceTime = rng.nextInt(DoubleMath.roundToInt(endTime * .8, RoundingMode.FLOOR)); b.addEvent(AddParcelEvent.create(Parcel.builder(g.getRandomNode(rng), g.getRandomNode(rng)) .orderAnnounceTime(announceTime).pickupTimeWindow(TimeWindow.create(announceTime, endTime)) .deliveryTimeWindow(TimeWindow.create(announceTime, endTime)).neededCapacity(0).buildDTO())); } b.addEvent(TimeOutEvent.create(endTime)).scenarioLength(endTime) .setStopCondition(StopConditions.limitedTime(endTime)); final Simulator sim = Simulator.builder() .addModel(ScenarioController.builder(b.build()) .withEventHandler(AddParcelEvent.class, AddParcelEvent.defaultHandler()) .withEventHandler(TimeOutEvent.class, TimeOutEvent.ignoreHandler()) .withEventHandler(AddVehicleEvent.class, new TimedEventHandler<AddVehicleEvent>() { @Override public void handleTimedEvent(AddVehicleEvent event, SimulatorAPI simulator) { simulator.register(new RandomVehicle(event.getVehicleDTO())); } })) .addModel(View.builder().withTitleAppendix("Wrapped GraphRoadModel UI test") .with(GraphRoadModelRenderer.builder().withMargin(1)).with(RoadUserRenderer.builder()) .withSimulatorEndTime(30 * 1000).withAutoPlay().withAutoClose()) .build(); sim.start(); }
From source file:com.github.rinde.rinsim.central.arrays.ArraysSolversTest.java
@Test public void travelTimeMatrix() { final Point p0 = new Point(0, 0); final Point p1 = new Point(10, 0); final Point p2 = new Point(10, 10); final Point p3 = new Point(0, 10); // input in kilometers, output in minutes (rounded up), speed 40 km/h final Measure<Double, Velocity> speed1 = Measure.valueOf(40d, KILOMETERS_PER_HOUR); final int[][] matrix1 = ArraysSolvers.toTravelTimeMatrix(asList(p0, p1, p2, p3), KILOMETER, speed1, MINUTE, RoundingMode.CEILING); assertArrayEquals(new int[] { 0, 15, 22, 15 }, matrix1[0]); assertArrayEquals(new int[] { 15, 0, 15, 22 }, matrix1[1]); assertArrayEquals(new int[] { 22, 15, 0, 15 }, matrix1[2]); assertArrayEquals(new int[] { 15, 22, 15, 0 }, matrix1[3]); final Point p4 = new Point(11, 3); // input in meters, output in milliseconds (round down), speed .0699 // m/ms/* w ww.j a v a 2 s. co m*/ final Measure<Double, Velocity> speed2 = Measure.valueOf(.0699, new ProductUnit<Velocity>(METER.divide(MILLI(SECOND)))); final int[][] matrix2 = ArraysSolvers.toTravelTimeMatrix(asList(p0, p1, p2, p3, p4), METER, speed2, MILLI(SECOND), RoundingMode.FLOOR); assertArrayEquals(new int[] { 0, 143, 202, 143, 163 }, matrix2[0]); assertArrayEquals(new int[] { 143, 0, 143, 202, 45 }, matrix2[1]); assertArrayEquals(new int[] { 202, 143, 0, 143, 101 }, matrix2[2]); assertArrayEquals(new int[] { 143, 202, 143, 0, 186 }, matrix2[3]); assertArrayEquals(new int[] { 163, 45, 101, 186, 0 }, matrix2[4]); }
From source file:com.turbospaces.model.TestEntity1.java
public void afterPropertiesSet(final String id) { s1 = "s1" + random.nextDouble(); s2 = "s2" + random.nextDouble(); s3 = "s3" + random.nextDouble(); s4 = "s4" + random.nextDouble(); l1 = random.nextLong();// www . j a v a 2 s . co m l2 = random.nextLong(); l3 = random.nextLong(); l4 = random.nextLong(); dt1 = new Date(System.currentTimeMillis() - 1000); dt2 = new Date(System.currentTimeMillis() + 1000); dt3 = new Date(dt1.getTime()); dt4 = new Date(dt2.getTime()); d1 = random.nextDouble(); d2 = random.nextDouble(); d3 = random.nextDouble(); d4 = random.nextDouble(); f1 = random.nextFloat(); f2 = random.nextFloat(); f3 = random.nextFloat(); f4 = random.nextFloat(); fi1 = random.nextInt(); fi2 = random.nextInt(); data1 = Integer.valueOf(random.nextInt()); uniqueIdentifier = id; mode = RoundingMode.FLOOR; autowire = Autowire.BY_TYPE; routing = "hash" + random.nextLong(); roundingModes = RoundingMode.values(); longs = Lists.newArrayList(); longs.add(Long.valueOf(1L)); longs.add(Long.valueOf(2L)); longs.add(Long.valueOf(3L)); b1 = random.nextBoolean(); b2 = random.nextBoolean(); b3 = random.nextBoolean(); b4 = random.nextBoolean(); sh1 = (short) random.nextInt(); sh2 = (short) random.nextInt(); sh3 = (short) random.nextInt(); sh4 = (short) random.nextInt(); dp1 = random.nextDouble(); dp2 = random.nextDouble(); dp3 = random.nextDouble(); dp4 = random.nextDouble(); fp1 = random.nextFloat(); fp2 = random.nextFloat(); fp3 = random.nextFloat(); fp4 = random.nextFloat(); cp1 = (char) random.nextInt(); cp2 = (char) random.nextInt(); cp3 = (char) random.nextInt(); cp4 = (char) random.nextInt(); lp1 = random.nextLong(); lp2 = random.nextLong(); }
From source file:com.github.rinde.rinsim.examples.demo.factory.FactoryExample.java
static void addPath(Graph<?> graph, Point... points) { final List<Point> newPoints = newArrayList(); for (int i = 0; i < points.length - 1; i++) { final double dist = Point.distance(points[i], points[i + 1]); final Point unit = Point.divide(Point.diff(points[i + 1], points[i]), dist); final int numPoints = DoubleMath.roundToInt(dist / POINT_DISTANCE, RoundingMode.FLOOR); for (int j = 0; j < numPoints; j++) { final double factor = j * POINT_DISTANCE; newPoints.add(new Point(points[i].x + factor * unit.x, points[i].y + factor * unit.y)); }// w w w . j a v a 2s .c om } newPoints.add(points[points.length - 1]); Graphs.addPath(graph, newPoints.toArray(new Point[newPoints.size()])); }
From source file:easycare.load.util.db.loader.UserDataLoader.java
private void createPaddingUsers(ContextOfCurrentLoad context, Organisation organisation, String organisationNumber) { BigDecimal numberOfPatientsPerOrg = context.numberOfPatientsInPassedOrg(organisation, organisationNumber); int numberOfPaddingUsers = numberOfPatientsPerOrg.divide(PADDING_FACTOR).setScale(0, RoundingMode.FLOOR) .intValue();/*from ww w . ja v a 2 s .c o m*/ List<Role> roles = newArrayList(seedData.getRole(RoleEnum.ROLE_CLINICIAN)); for (int i = 0; i < numberOfPaddingUsers; i++) { buildUser(context, String.format("paddy%s-%d", organisationNumber, i), context.getFaker().firstName(), context.getFaker().lastName(), organisation, roles, organisationNumber); } }
From source file:com.reizes.shiva.utils.CommonUtil.java
/** * ??? 100 ? ?? ? ( ?)// w ww .j ava 2 s. c o m * ? null ? 0 ? 0.0 ( API ) * @param input ? * @return ? ? ? ? */ public static String div100(Long input) { if (input == null || input == 0) { return "0.0"; } Double fl = input / 100d; DecimalFormat df = new DecimalFormat("#.##"); df.setRoundingMode(RoundingMode.FLOOR); return df.format(fl); }
From source file:com.reizes.shiva.utils.CommonUtil.java
/** * ? ( ?)/* w w w . java 2 s . co m*/ * @param input * @return */ public static String decimalPointTwo(Float input) { if (input == null || input == 0) { return "0.0"; } DecimalFormat df = new DecimalFormat("#.##"); df.setRoundingMode(RoundingMode.FLOOR); return df.format(input); }