Search in sources :

Example 31 with BigDecimal

use of android.icu.math.BigDecimal in project j2objc by google.

the class UniversalTimeScale method toBigDecimal.

/**
 * Convert a datetime from the universal time scale to a <code>BigDecimal</code> in the given time scale.
 *
 * @param universalTime The datetime in the universal time scale
 * @param timeScale The time scale to convert to
 *
 * @return The datetime converted to the given time scale
 */
public static BigDecimal toBigDecimal(long universalTime, int timeScale) {
    TimeScaleData data = getTimeScaleData(timeScale);
    BigDecimal universal = new BigDecimal(universalTime);
    BigDecimal units = new BigDecimal(data.units);
    BigDecimal epochOffset = new BigDecimal(data.epochOffset);
    return universal.divide(units, BigDecimal.ROUND_HALF_UP).subtract(epochOffset);
}
Also used : BigDecimal(android.icu.math.BigDecimal)

Example 32 with BigDecimal

use of android.icu.math.BigDecimal in project j2objc by google.

the class UniversalTimeScale method toBigDecimalTrunc.

/**
 * Convert a time in the Universal Time Scale into another time
 * scale. The division used to do the conversion rounds down.
 *
 * NOTE: This is an internal routine used by the tool that
 * generates the to and from limits. Use it at your own risk.
 *
 * @param universalTime the time in the Universal Time scale
 * @param timeScale the time scale to convert to
 * @return the time in the given time scale
 *
 * @deprecated This API is ICU internal only.
 * @hide draft / provisional / internal are hidden on Android
 */
@Deprecated
public static BigDecimal toBigDecimalTrunc(BigDecimal universalTime, int timeScale) {
    TimeScaleData data = getTimeScaleData(timeScale);
    BigDecimal units = new BigDecimal(data.units);
    BigDecimal epochOffset = new BigDecimal(data.epochOffset);
    return universalTime.divide(units, BigDecimal.ROUND_DOWN).subtract(epochOffset);
}
Also used : BigDecimal(android.icu.math.BigDecimal)

Example 33 with BigDecimal

use of android.icu.math.BigDecimal in project j2objc by google.

the class UniversalTimeScale method bigDecimalFrom.

/**
 * Convert a <code>long</code> datetime from the given time scale to the universal time scale.
 * All calculations are done using <code>BigDecimal</code> to guarantee that the value
 * does not go out of range.
 *
 * @param otherTime The <code>long</code> datetime
 * @param timeScale The time scale to convert from
 *
 * @return The datetime converted to the universal time scale
 */
public static BigDecimal bigDecimalFrom(long otherTime, int timeScale) {
    TimeScaleData data = getTimeScaleData(timeScale);
    BigDecimal other = new BigDecimal(otherTime);
    BigDecimal units = new BigDecimal(data.units);
    BigDecimal epochOffset = new BigDecimal(data.epochOffset);
    return other.add(epochOffset).multiply(units);
}
Also used : BigDecimal(android.icu.math.BigDecimal)

Aggregations

BigDecimal (android.icu.math.BigDecimal)33 Test (org.junit.Test)19 DecimalFormat (android.icu.text.DecimalFormat)10 CompactDecimalFormat (android.icu.text.CompactDecimalFormat)9 BigInteger (java.math.BigInteger)5 DecimalFormatSymbols (android.icu.text.DecimalFormatSymbols)4 ULocale (android.icu.util.ULocale)4 ParseException (java.text.ParseException)4 NumberFormat (android.icu.text.NumberFormat)3 RuleBasedNumberFormat (android.icu.text.RuleBasedNumberFormat)3 CurrencyAmount (android.icu.util.CurrencyAmount)3 MeasureFormat (android.icu.text.MeasureFormat)2 FieldPosition (java.text.FieldPosition)2 FieldContainer (android.icu.dev.test.format.IntlTestDecimalFormatAPIC.FieldContainer)1 Currency (android.icu.util.Currency)1 AttributedCharacterIterator (java.text.AttributedCharacterIterator)1 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1