List of usage examples for org.apache.commons.lang3.math Fraction getDenominator
public int getDenominator()
Gets the denominator part of the fraction.
From source file:gmgen.plugin.PlayerCharacterOutput.java
/** * TODO Much of this code is repeated in CRToken, Race, Combatant and PlayerCharacterOutput * /*from ww w . j a va 2 s . c o m*/ * @return An output version of the CR */ public String getCR() { Integer calcCR = display.calcCR(); float cr = (calcCR == null) ? -1 : calcCR; String retString = ""; // If the CR is a fractional CR then we convert to a 1/x format if ((cr > 0) && (cr < 1)) { Fraction fraction = Fraction.getFraction(cr); // new Fraction(CR); int denominator = fraction.getDenominator(); int numerator = fraction.getNumerator(); retString = numerator + "/" + denominator; } else if ((cr >= 1) || (cr == 0)) { int newCr = -99; String crAsString = Float.toString(cr); String decimalPlaceValue = crAsString.substring(crAsString.length() - 2); if (decimalPlaceValue.equals(".0")) { newCr = (int) cr; } retString += ((newCr > -99) ? newCr : cr); } return retString; }
From source file:org.eclipse.tracecompass.tmf.ui.markers.PeriodicMarkerEventSource.java
private Reference adjustReference(Reference baseReference, long time) { long offsetIndex = (long) ((time - baseReference.time) / fPeriod); long offsetTime = 0; Fraction fraction = fPeriodFraction; if (fraction != null) { /*//from w w w .j av a 2 s . co m * If period = int num/den, find an offset index that is an exact * multiple of den and calculate index * period = (index * int) + * (index / den * num), all exact calculations. */ offsetIndex = offsetIndex - offsetIndex % fraction.getDenominator(); offsetTime = offsetIndex * fPeriodInteger + offsetIndex / fraction.getDenominator() * fraction.getNumerator(); } else { /* * Couldn't compute fractional part as fraction, use simple * multiplication but with possible rounding error. */ offsetTime = Math.round(offsetIndex * fPeriod); } Reference reference = new Reference(baseReference.time + offsetTime, baseReference.index + offsetIndex); return reference; }
From source file:org.zkoss.ganttz.DatesMapperOnInterval.java
private int toPixels(Fraction proportion) { try {//from w w w .j a va 2s .c o m return proportion.multiplyBy(Fraction.getFraction(horizontalSize, 1)).intValue(); } catch (ArithmeticException e) { double d = Math.log10(horizontalSize); int scale = (int) d + 1; BigDecimal quotient = new BigDecimal(proportion.getNumerator()) .divide(new BigDecimal(proportion.getDenominator()), scale, RoundingMode.HALF_UP); return quotient.multiply(new BigDecimal(horizontalSize)).intValue(); } }
From source file:pcgen.system.PCGenTaskExecutor.java
@Override public void progressChanged(PCGenTaskEvent event) { if (currentTask.getMaximum() == 0) { return;// ww w . ja va 2 s .com } Fraction progress = Fraction.getFraction(currentTask.getProgress(), currentTask.getMaximum()); progress = progress.multiplyBy(progressMultiplier); progress = baseProgress.add(progress); setValues(currentTask.getMessage(), progress.getNumerator(), progress.getDenominator()); }
From source file:plugin.initiative.XMLCombatant.java
/** * /* w w w . j ava2 s . com*/ * TODO Much of this code is repeated in CRToken, Race, XMLCombatant and PlayerCharacterOutput * * <p>Gets the CR value for the character for output</p> * @return CR value */ public String getCRForOutput() { String retString = ""; String crAsString = Float.toString(cr); String decimalPlaceValue = crAsString.substring(crAsString.length() - 2); // If the CR is a fractional CR then we convert to a 1/x format if (cr > 0 && cr < 1) { Fraction fraction = Fraction.getFraction(cr); // new Fraction(CR); int denominator = fraction.getDenominator(); int numerator = fraction.getNumerator(); retString = numerator + "/" + denominator; } else if (cr >= 1 || cr == 0) { int newCr = -99; if (decimalPlaceValue.equals(".0")) { newCr = (int) cr; } if (newCr > -99) { retString = retString + newCr; } else { retString = retString + cr; } } return retString; }