Class Formats
- java.lang.Object
-
- com.syntifi.near.api.common.helper.Formats
-
public class Formats extends java.lang.Object
Helper methods for formatting- Since:
- 0.2.0
- Author:
- Alexandre Carvalho, Andre Bertolace
-
-
Field Summary
Fields Modifier and Type Field Description static java.math.BigInteger
NEAR_NOMINATION
Number of indivisible units in one NEAR.static int
NEAR_NOMINATION_EXP
Exponent for calculating how many indivisible units are there in one NEAR.
-
Constructor Summary
Constructors Constructor Description Formats()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
cleanupAmount(java.lang.String amount)
Removes commas from the inputstatic java.lang.String
formatNearAmount(java.lang.String balance, java.lang.Integer fracDigits)
Convert account balance value from internal indivisible units to NEAR.static java.lang.String
formatWithCommas(java.lang.String value)
Returns a human-readable value with commasstatic java.lang.String
padEnd(java.lang.String input, int maxLength, char fillChar)
Pads an input string from its end with a char until it reaches a max lengthstatic java.lang.String
padStart(java.lang.String input, int maxLength, char fillChar)
Pads an input string from its start with a char until it reaches a max lengthstatic java.lang.String
parseNearAmount(java.lang.String amount)
Convert human-readable NEAR amount to internal indivisible units.static java.lang.String
trimLeadingZeroes(java.lang.String value)
Removes leading zeroes from an inputstatic java.lang.String
trimTrailingZeroes(java.lang.String value)
Removes .000… from an input
-
-
-
Field Detail
-
NEAR_NOMINATION_EXP
public static int NEAR_NOMINATION_EXP
Exponent for calculating how many indivisible units are there in one NEAR. SeeNEAR_NOMINATION
.
-
NEAR_NOMINATION
public static java.math.BigInteger NEAR_NOMINATION
Number of indivisible units in one NEAR. Derived fromNEAR_NOMINATION_EXP
.
-
-
Method Detail
-
formatNearAmount
public static java.lang.String formatNearAmount(java.lang.String balance, java.lang.Integer fracDigits)
Convert account balance value from internal indivisible units to NEAR. 1 NEAR is defined byNEAR_NOMINATION
. Effectively this divides given amount byNEAR_NOMINATION
.- Parameters:
balance
- decimal string representing balance in smallest non-divisible NEAR units (as specified byNEAR_NOMINATION
)fracDigits
- number of fractional digits to preserve in formatted string. Balance is rounded to match given number of digits.- Returns:
- Value in Ⓝ
-
parseNearAmount
public static java.lang.String parseNearAmount(java.lang.String amount)
Convert human-readable NEAR amount to internal indivisible units. Effectively this multiplies given amount byNEAR_NOMINATION
.- Parameters:
amount
- decimal string (potentially fractional) denominated in NEAR.- Returns:
- The parsed yoctoⓃ amount or null if no amount was passed in
-
padStart
public static java.lang.String padStart(java.lang.String input, int maxLength, char fillChar)
Pads an input string from its start with a char until it reaches a max length- Parameters:
input
- the input stringmaxLength
- the max length to reachfillChar
- the char to fill- Returns:
- the padded string
-
padEnd
public static java.lang.String padEnd(java.lang.String input, int maxLength, char fillChar)
Pads an input string from its end with a char until it reaches a max length- Parameters:
input
- the input stringmaxLength
- the max length to reachfillChar
- the char to fill- Returns:
- the padded string
-
cleanupAmount
public static java.lang.String cleanupAmount(java.lang.String amount)
Removes commas from the input- Parameters:
amount
- A value or amount that may contain commas- Returns:
- string The cleaned value
-
trimTrailingZeroes
public static java.lang.String trimTrailingZeroes(java.lang.String value)
Removes .000… from an input- Parameters:
value
- A value that may contain trailing zeroes in the decimals place- Returns:
- string The value without the trailing zeros
-
trimLeadingZeroes
public static java.lang.String trimLeadingZeroes(java.lang.String value)
Removes leading zeroes from an input- Parameters:
value
- A value that may contain leading zeroes- Returns:
- string The value without the leading zeroes
-
formatWithCommas
public static java.lang.String formatWithCommas(java.lang.String value)
Returns a human-readable value with commas- Parameters:
value
- A value that may not contain commas- Returns:
- string A value with commas
-
-