-
public final class CurrencyFormatterKt
-
-
Method Summary
Modifier and Type Method Description final static StringconvertZatoshiToZecString(Zatoshi $self, Integer maxDecimals, Integer minDecimals)Format a Zatoshi value into ZEC with the given number of digits, represented as a string. final static StringtoZecString(Double $self, Integer maxDecimals, Integer minDecimals)Format a ZEC value into ZEC with the given number of digits, represented as a string. final static StringtoZecString(BigDecimal $self, Integer maxDecimals, Integer minDecimals)Format a Zatoshi value into ZEC with the given number of decimal places, represented as a string. final static StringtoUsdString(Double $self, Integer maxDecimals, Integer minDecimals)Format a USD value into USD with the given number of digits, represented as a string. final static StringtoUsdString(BigDecimal $self, Integer maxDecimals, Integer minDecimals)Format a USD value into USD with the given number of decimal places, represented as a string. final static NumberFormatcurrencyFormatter(Integer maxDecimals, Integer minDecimals)Create a number formatter for use with converting currency to strings. final static BigDecimalconvertZatoshiToZec(Zatoshi $self, Integer scale)Convert a Zatoshi value into ZEC, right-padded to the given number of fraction digits, represented as a BigDecimal in order to preserve rounding that minimizes cumulative error when applied repeatedly over a sequence of calculations. final static ZatoshiconvertZecToZatoshi(BigDecimal $self)Convert a ZEC value into Zatoshi. final static ZatoshiconvertZecToZatoshi(Double $self, Integer decimals)Format a Double ZEC value as a Long Zatoshi value, by first converting to ZEC with the given precision. final static BigDecimaltoZec(Double $self, Integer decimals)Format a Double ZEC value as a BigDecimal ZEC value, right-padded to the given number of fraction digits. final static BigDecimaltoZec(BigDecimal $self, Integer decimals)Format a BigDecimal ZEC value as a BigDecimal ZEC value, right-padded to the given number of fraction digits. final static BigDecimaltoUsd(Double $self, Integer decimals)Format a Double USD value as a BigDecimal USD value, right-padded to the given number of fraction digits. final static BigDecimaltoUsd(BigDecimal $self, Integer decimals)Format a BigDecimal USD value as a BigDecimal USD value, right-padded to the given number of fraction digits. final static BigDecimalconvertZecToUsd(BigDecimal $self, BigDecimal zecPrice)Convert this ZEC value to USD, using the given price per ZEC. final static BigDecimalconvertUsdToZec(BigDecimal $self, BigDecimal zecPrice)Convert this USD value to ZEC, using the given price per ZEC. final static DoubleconvertUsdToZec(Double $self, Double zecPrice)Convert this USD value to ZEC, using the given price per ZEC. final static BigDecimalconvertCurrency(BigDecimal $self, BigDecimal zecPrice, Boolean isUsd)Convert this value from one currency to the other, based on given price and whether this value is USD. final static BigDecimalsafelyConvertToBigDecimal(String $self, Character decimalSeparator)Parse this string into a BigDecimal, ignoring all non numeric characters. final static StringtoAbbreviatedAddress(String $self, Integer startLength, Integer endLength)Abbreviates this string which is assumed to be an address. final static BooleanisShielded(String $self)Convenience function that returns true when this string starts with 'z'. -
-
Method Detail
-
convertZatoshiToZecString
final static String convertZatoshiToZecString(Zatoshi $self, Integer maxDecimals, Integer minDecimals)
Format a Zatoshi value into ZEC with the given number of digits, represented as a string. Start with Zatoshi -> End with ZEC.
- Parameters:
maxDecimals- the number of decimal places to use in the format.minDecimals- the minimum number of digits to allow to the right of the decimal.
-
toZecString
final static String toZecString(Double $self, Integer maxDecimals, Integer minDecimals)
Format a ZEC value into ZEC with the given number of digits, represented as a string. Start with ZEC -> End with ZEC.
- Parameters:
maxDecimals- the number of decimal places to use in the format.minDecimals- the minimum number of digits to allow to the right of the decimal.
-
toZecString
final static String toZecString(BigDecimal $self, Integer maxDecimals, Integer minDecimals)
Format a Zatoshi value into ZEC with the given number of decimal places, represented as a string. Start with ZeC -> End with ZEC.
- Parameters:
maxDecimals- the number of decimal places to use in the format.minDecimals- the minimum number of digits to allow to the right of the decimal.
-
toUsdString
final static String toUsdString(Double $self, Integer maxDecimals, Integer minDecimals)
Format a USD value into USD with the given number of digits, represented as a string. Start with USD -> end with USD.
- Parameters:
maxDecimals- the number of decimal places to use in the format.minDecimals- the minimum number of digits to allow to the right of the decimal.
-
toUsdString
final static String toUsdString(BigDecimal $self, Integer maxDecimals, Integer minDecimals)
Format a USD value into USD with the given number of decimal places, represented as a string. Start with USD -> end with USD.
- Parameters:
maxDecimals- the number of decimal places to use in the format.minDecimals- the minimum number of digits to allow to the right of the decimal.
-
currencyFormatter
final static NumberFormat currencyFormatter(Integer maxDecimals, Integer minDecimals)
Create a number formatter for use with converting currency to strings. This probably isn't needed externally since the other formatting functions leverage this, instead. Leverages the default rounding mode for ZEC found in ZEC_FORMATTER.
- Parameters:
maxDecimals- the number of decimal places to use in the format.minDecimals- the minimum number of digits to allow to the right of the decimal.
-
convertZatoshiToZec
final static BigDecimal convertZatoshiToZec(Zatoshi $self, Integer scale)
Convert a Zatoshi value into ZEC, right-padded to the given number of fraction digits, represented as a BigDecimal in order to preserve rounding that minimizes cumulative error when applied repeatedly over a sequence of calculations. Start with Zatoshi -> End with ZEC.
- Parameters:
scale- the number of digits to the right of the decimal place.
-
convertZecToZatoshi
final static Zatoshi convertZecToZatoshi(BigDecimal $self)
Convert a ZEC value into Zatoshi. Start with ZEC -> End with Zatoshi.
-
convertZecToZatoshi
final static Zatoshi convertZecToZatoshi(Double $self, Integer decimals)
Format a Double ZEC value as a Long Zatoshi value, by first converting to ZEC with the given precision. Start with ZEC -> End with Zatoshi.
- Parameters:
decimals- the scale to use for the intermediate BigDecimal.
-
toZec
final static BigDecimal toZec(Double $self, Integer decimals)
Format a Double ZEC value as a BigDecimal ZEC value, right-padded to the given number of fraction digits. Start with ZEC -> End with ZEC.
- Parameters:
decimals- the scale to use for the resulting BigDecimal.
-
toZec
final static BigDecimal toZec(BigDecimal $self, Integer decimals)
Format a BigDecimal ZEC value as a BigDecimal ZEC value, right-padded to the given number of fraction digits. Start with ZEC -> End with ZEC.
- Parameters:
decimals- the scale to use for the resulting BigDecimal.
-
toUsd
final static BigDecimal toUsd(Double $self, Integer decimals)
Format a Double USD value as a BigDecimal USD value, right-padded to the given number of fraction digits. Start with USD -> End with USD.
- Parameters:
decimals- the scale to use for the resulting BigDecimal.
-
toUsd
final static BigDecimal toUsd(BigDecimal $self, Integer decimals)
Format a BigDecimal USD value as a BigDecimal USD value, right-padded to the given number of fraction digits. Start with USD -> End with USD.
- Parameters:
decimals- the scale to use for the resulting BigDecimal.
-
convertZecToUsd
final static BigDecimal convertZecToUsd(BigDecimal $self, BigDecimal zecPrice)
Convert this ZEC value to USD, using the given price per ZEC. Start with ZEC -> End with USD.
- Parameters:
zecPrice- the current price of ZEC represented as USD per ZEC
-
convertUsdToZec
final static BigDecimal convertUsdToZec(BigDecimal $self, BigDecimal zecPrice)
Convert this USD value to ZEC, using the given price per ZEC. Start with USD -> End with ZEC.
- Parameters:
zecPrice- the current price of ZEC represented as USD per ZEC.
-
convertUsdToZec
final static Double convertUsdToZec(Double $self, Double zecPrice)
Convert this USD value to ZEC, using the given price per ZEC. Start with USD -> End with ZEC.
- Parameters:
zecPrice- the current price of ZEC represented as USD per ZEC.
-
convertCurrency
final static BigDecimal convertCurrency(BigDecimal $self, BigDecimal zecPrice, Boolean isUsd)
Convert this value from one currency to the other, based on given price and whether this value is USD. If starting with USD -> End with ZEC. If starting with ZEC -> End with USD.
-
safelyConvertToBigDecimal
final static BigDecimal safelyConvertToBigDecimal(String $self, Character decimalSeparator)
Parse this string into a BigDecimal, ignoring all non numeric characters.
-
toAbbreviatedAddress
final static String toAbbreviatedAddress(String $self, Integer startLength, Integer endLength)
Abbreviates this string which is assumed to be an address.
- Parameters:
startLength- the number of characters to show before the elipsis.endLength- the number of characters to show after the elipsis.
-
isShielded
final static Boolean isShielded(String $self)
Convenience function that returns true when this string starts with 'z'.
-
-
-
-