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