Java Code Examples for org.bitcoinj.utils.Fiat#valueOf()

The following examples show how to use org.bitcoinj.utils.Fiat#valueOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Price.java    From bisq-core with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Parse the Bitcoin {@code Price} given a {@code currencyCode} and {@code inputValue}.
 *
 * @param currencyCode The currency code to parse, e.g "USD" or "LTC".
 * @param value        The value to parse.
 * @return             The parsed Price.
 */
public static Price valueOf(String currencyCode, long value) {
    if (CurrencyUtil.isFiatCurrency(currencyCode)) {
        return new Price(Fiat.valueOf(currencyCode, value));
    } else {
        return new Price(Altcoin.valueOf(currencyCode, value));
    }
}
 
Example 2
Source File: BSFormatter.java    From bisq-core with GNU Affero General Public License v3.0 5 votes vote down vote up
protected Fiat parseToFiat(String input, String currencyCode) {
    if (input != null && input.length() > 0) {
        try {
            return Fiat.parseFiat(currencyCode, cleanDoubleInput(input));
        } catch (Exception e) {
            log.warn("Exception at parseToFiat: " + e.toString());
            return Fiat.valueOf(currencyCode, 0);
        }

    } else {
        return Fiat.valueOf(currencyCode, 0);
    }
}
 
Example 3
Source File: BSFormatter.java    From bisq-core with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Converts to a fiat with max. 2 decimal places. Last place gets rounded.
 * 0.234 -> 0.23
 * 0.235 -> 0.24
 *
 * @param input
 * @return
 */

public Fiat parseToFiatWithPrecision(String input, String currencyCode) {
    if (input != null && input.length() > 0) {
        try {
            return parseToFiat(new BigDecimal(cleanDoubleInput(input)).setScale(2, BigDecimal.ROUND_HALF_UP).toString(),
                    currencyCode);
        } catch (Throwable t) {
            log.warn("Exception at parseToFiatWithPrecision: " + t.toString());
            return Fiat.valueOf(currencyCode, 0);
        }

    }
    return Fiat.valueOf(currencyCode, 0);
}
 
Example 4
Source File: GaService.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
private Coin getSpendingLimitAmount() {
    final Coin unconverted = mLimitsData.getCoin("total");
    if (isElements())
        return unconverted.multiply(100);
    if (!mLimitsData.getBool("is_fiat"))
        return unconverted;
    // Fiat class uses SMALLEST_UNIT_EXPONENT units (10^4), our limit is
    // held in 10^2 (e.g. cents) units, hence we * 100 below.
    final Fiat fiatLimit = Fiat.valueOf("???", mLimitsData.getLong("total") * 100);
    return getFiatRate().fiatToCoin(fiatLimit);
}
 
Example 5
Source File: Price.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Parse the Bitcoin {@code Price} given a {@code currencyCode} and {@code inputValue}.
 *
 * @param currencyCode The currency code to parse, e.g "USD" or "LTC".
 * @param value        The value to parse.
 * @return The parsed Price.
 */
public static Price valueOf(String currencyCode, long value) {
    if (CurrencyUtil.isFiatCurrency(currencyCode)) {
        return new Price(Fiat.valueOf(currencyCode, value));
    } else {
        return new Price(Altcoin.valueOf(currencyCode, value));
    }
}
 
Example 6
Source File: GaService.java    From GreenBits with GNU General Public License v3.0 4 votes vote down vote up
public ExchangeRate getFiatRate() {
    final long rate = new BigDecimal(mFiatRate).movePointRight(Fiat.SMALLEST_UNIT_EXPONENT)
                                               .toBigInteger().longValue();
    return new ExchangeRate(Fiat.valueOf("???", rate));
}