use of java.math.BigDecimal in project j2objc by google.
the class DecimalFormatTest method test_formatToCharacterIterator_veryLarge.
public void test_formatToCharacterIterator_veryLarge() throws Exception {
AttributedCharacterIterator iterator;
int[] runStarts;
int[] runLimits;
String result;
char current;
Number number = new BigDecimal("1.23456789E1234");
assertEquals("1.23456789E+1234", number.toString());
iterator = new DecimalFormat().formatToCharacterIterator(number);
runStarts = new int[] { 0, 0, 2, 3, 3, 3, 6, 7, 7, 7, 10, 11, 11, 11, 14 };
runLimits = new int[] { 2, 2, 3, 6, 6, 6, 7, 10, 10, 10, 11, 14, 14, 14, 15 };
// 000,000,000,000....
result = "12,345,678,900,";
current = iterator.current();
for (int i = 0; i < runStarts.length; i++) {
assertEquals("wrong start @" + i, runStarts[i], iterator.getRunStart());
assertEquals("wrong limit @" + i, runLimits[i], iterator.getRunLimit());
assertEquals("wrong char @" + i, result.charAt(i), current);
current = iterator.next();
}
assertEquals(0, iterator.getBeginIndex());
assertEquals(1646, iterator.getEndIndex());
}
use of java.math.BigDecimal in project gradle by gradle.
the class CompositeTestResults method getSuccessRate.
public Number getSuccessRate() {
if (getRunTestCount() == 0) {
return null;
}
BigDecimal runTests = BigDecimal.valueOf(getRunTestCount());
BigDecimal successful = BigDecimal.valueOf(getRunTestCount() - getFailureCount());
return successful.divide(runTests, 2, BigDecimal.ROUND_DOWN).multiply(BigDecimal.valueOf(100)).intValue();
}
use of java.math.BigDecimal in project groovy-core by groovy.
the class DefaultGroovyMethods method downto.
/**
* Iterates from this number down to the given number, inclusive,
* decrementing by one each time.
*
* @param self a BigInteger
* @param to the end number
* @param closure the code to execute for each number
* @since 1.0
*/
public static void downto(BigInteger self, Number to, @ClosureParams(FirstParam.class) Closure closure) {
if (to instanceof BigDecimal) {
// That's what you get for "1.0".
final BigDecimal one = BigDecimal.valueOf(10, 1);
final BigDecimal to1 = (BigDecimal) to;
final BigDecimal selfD = new BigDecimal(self);
if (selfD.compareTo(to1) >= 0) {
for (BigDecimal i = selfD; i.compareTo(to1) >= 0; i = i.subtract(one)) {
closure.call(i.toBigInteger());
}
} else
throw new GroovyRuntimeException(MessageFormat.format("The argument ({0}) to downto() cannot be greater than the value ({1}) it''s called on.", to, self));
} else if (to instanceof BigInteger) {
final BigInteger one = BigInteger.valueOf(1);
final BigInteger to1 = (BigInteger) to;
if (self.compareTo(to1) >= 0) {
for (BigInteger i = self; i.compareTo(to1) >= 0; i = i.subtract(one)) {
closure.call(i);
}
} else
throw new GroovyRuntimeException(MessageFormat.format("The argument ({0}) to downto() cannot be greater than the value ({1}) it''s called on.", to, self));
} else {
final BigInteger one = BigInteger.valueOf(1);
final BigInteger to1 = new BigInteger(to.toString());
if (self.compareTo(to1) >= 0) {
for (BigInteger i = self; i.compareTo(to1) >= 0; i = i.subtract(one)) {
closure.call(i);
}
} else
throw new GroovyRuntimeException(MessageFormat.format("The argument ({0}) to downto() cannot be greater than the value ({1}) it''s called on.", to, self));
}
}
use of java.math.BigDecimal in project groovy-core by groovy.
the class RangeTest method testGet.
public void testGet() {
Range r = createRange(10, 20);
for (int i = 0; i < 10; i++) {
Integer value = (Integer) r.get(i);
assertEquals("Item at index: " + i, i + 10, value.intValue());
}
r = createRange(new BigDecimal("3.2"), new BigDecimal("9.9"));
for (int i = 0; i < r.size(); i++) {
BigDecimal value = (BigDecimal) r.get(i);
assertEquals("Item at index: " + i, new BigDecimal("3.2").add(new BigDecimal("" + i)), value);
}
}
use of java.math.BigDecimal in project groovy-core by groovy.
the class RangeTest method testIterator.
public void testIterator() {
Range r = createRange(5, 11);
int i = 5;
for (Iterator it = r.iterator(); it.hasNext(); ) {
assertEquals("equals to " + i, new Integer(i), (Integer) (it.next()));
i++;
}
r = createRange(new BigDecimal("5.0"), new BigDecimal("11.0"));
BigDecimal one = new BigDecimal("1.0");
BigDecimal val = new BigDecimal("5.0");
for (Iterator it = r.iterator(); it.hasNext(); ) {
assertEquals("equals to " + val, val, (BigDecimal) (it.next()));
val = val.add(one);
}
}
Aggregations