@Test public void shouldKeepSignificantFigures() { assertThat(ops.keepSignificantFigures(0, 2), is(0)); assertThat(ops.keepSignificantFigures(1201234, 5), is(1201200)); assertThat(ops.keepSignificantFigures(1201254, 5), is(1201300)); assertThat(ops.keepSignificantFigures(1201234, 4), is(1201000)); assertThat(ops.keepSignificantFigures(1201234, 3), is(1200000)); assertThat(ops.keepSignificantFigures(1201234, 2), is(1200000)); assertThat(ops.keepSignificantFigures(1201234, 1), is(1000000)); assertThat(ops.keepSignificantFigures(-1320, 2), is(-1300)); }
@Override public Integer keepSignificantFigures( Integer value, int numSigFigs ) { if (numSigFigs < 0) return value; if (numSigFigs == 0) return 0; int currentExp = getExponentInScientificNotation(value); int decimalShift = -currentExp + numSigFigs - 1; return roundUp(value, decimalShift); }
IntegerOperations implements MathOperations<Integer>, Comparator<Integer> { @Override public Integer keepSignificantFigures( Integer value, int numSigFigs ) { if (numSigFigs < 0) return value; if (numSigFigs == 0) return 0; int currentExp = getExponentInScientificNotation(value); int decimalShift = -currentExp + numSigFigs - 1; return roundUp(value, decimalShift); } }
IntegerOperations implements MathOperations<Integer>, Comparator<Integer> { @Override public Integer keepSignificantFigures( Integer value, int numSigFigs ) { if (numSigFigs < 0) return value; if (numSigFigs == 0) return 0; int currentExp = getExponentInScientificNotation(value); int decimalShift = -currentExp + numSigFigs - 1; return roundUp(value, decimalShift); }  }
IntegerOperations implements MathOperations<Integer>, Comparator<Integer> { @Override public Integer keepSignificantFigures( Integer value, int numSigFigs ) { if (numSigFigs < 0) return value; if (numSigFigs == 0) return 0; int currentExp = getExponentInScientificNotation(value); int decimalShift = -currentExp + numSigFigs - 1; return roundUp(value, decimalShift); }  @Override Class<Integer> getOperandClass(); @Override Integer add( Integer value1,
                        Integer value2 ); @Override Integer subtract( Integer value1,
                             Integer value2 ); @Override Integer multiply( Integer value1,
                             Integer value2 ); @Override double divide( Integer value1,
                          Integer value2 ); @Override Integer negate( Integer value ); @Override Integer increment( Integer value ); @Override Integer maximum( Integer value1,
                            Integer value2 ); @Override Integer minimum( Integer value1,
                            Integer value2 ); @Override int compare( Integer value1,
                        Integer value2 ); @Override BigDecimal asBigDecimal( Integer value ); @Override Integer fromBigDecimal( BigDecimal value ); @Override Integer createZeroValue(); @Override Integer create( int value ); @Override Integer create( long value ); @Override Integer create( double value ); @Override double sqrt( Integer value ); @Override Comparator<Integer> getComparator(); @Override Integer random( Integer minimum,
                           Integer maximum,
                           Random rng ); @Override double doubleValue( Integer value ); @Override float floatValue( Integer value ); @Override int intValue( Integer value ); @Override long longValue( Integer value ); @Override short shortValue( Integer value ); @Override int getExponentInScientificNotation( Integer value ); @Override Integer roundUp( Integer value,
                            int decimalShift ); @Override Integer roundDown( Integer value,
                              int decimalShift ); @Override Integer keepSignificantFigures( Integer value,
                                           int numSigFigs ); }
IntegerOperations implements MathOperations<Integer>, Comparator<Integer> { @Override public Integer keepSignificantFigures( Integer value, int numSigFigs ) { if (numSigFigs < 0) return value; if (numSigFigs == 0) return 0; int currentExp = getExponentInScientificNotation(value); int decimalShift = -currentExp + numSigFigs - 1; return roundUp(value, decimalShift); }  @Override Class<Integer> getOperandClass(); @Override Integer add( Integer value1,
                        Integer value2 ); @Override Integer subtract( Integer value1,
                             Integer value2 ); @Override Integer multiply( Integer value1,
                             Integer value2 ); @Override double divide( Integer value1,
                          Integer value2 ); @Override Integer negate( Integer value ); @Override Integer increment( Integer value ); @Override Integer maximum( Integer value1,
                            Integer value2 ); @Override Integer minimum( Integer value1,
                            Integer value2 ); @Override int compare( Integer value1,
                        Integer value2 ); @Override BigDecimal asBigDecimal( Integer value ); @Override Integer fromBigDecimal( BigDecimal value ); @Override Integer createZeroValue(); @Override Integer create( int value ); @Override Integer create( long value ); @Override Integer create( double value ); @Override double sqrt( Integer value ); @Override Comparator<Integer> getComparator(); @Override Integer random( Integer minimum,
                           Integer maximum,
                           Random rng ); @Override double doubleValue( Integer value ); @Override float floatValue( Integer value ); @Override int intValue( Integer value ); @Override long longValue( Integer value ); @Override short shortValue( Integer value ); @Override int getExponentInScientificNotation( Integer value ); @Override Integer roundUp( Integer value,
                            int decimalShift ); @Override Integer roundDown( Integer value,
                              int decimalShift ); @Override Integer keepSignificantFigures( Integer value,
                                           int numSigFigs );  }