new Soroban()
+ + + + + +Soroban helper class +formatting, parsing, and etc
+-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- Source: +
- + + + + + + + +
Methods
+ + + +(static) formatTokenAmount(amount, decimals) → {string}
+ + + + + +All arithmetic inside the contract is performed on integers to +avoid potential precision and consistency issues of floating-point
+This function takes the smart contract value and its decimals (if the token has any) and returns a display value
+-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- Source: +
- + + + + + + + +
Parameters:
+ + +Name | + + +Type | + + + + + +Description | +
---|---|---|
amount |
+
+
+
+
+
+string
+
+
+
+ |
+
+
+
+
+
+
+ the token amount you want to display + + |
+
decimals |
+
+
+
+
+
+number
+
+
+
+ |
+
+
+
+
+
+
+ specify how many decimal places a token has + + |
+
Returns:
+ + + +-
+
- + Type: + +
-
+
+
string
+ + +
+
-
+
- display value +
(static) parseTokenAmount(value, decimals) → {string}
+ + + + + +parse token amount to use it on smart contract
+This function takes the display value and its decimals (if the token has +any) and returns a string that'll be used within the smart contract.
+-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- Source: +
- + + + + + + + +
Parameters:
+ + +Name | + + +Type | + + + + + +Description | +
---|---|---|
value |
+
+
+
+
+
+string
+
+
+
+ |
+
+
+
+
+
+
+ the token amount you want to use it on smart contract + + |
+
decimals |
+
+
+
+
+
+number
+
+
+
+ |
+
+
+
+
+
+
+ specify how many decimal places a token has + + |
+
Returns:
+ + + +-
+
- + Type: + +
-
+
+
string
+ + +
+
-
+
- smart contract value +
Example
+ +const displayValueAmount = "123.4560"
+const parsedAmountForSmartContract = parseTokenAmount("123.4560", 5);
+parsedAmountForSmartContract === "12345600"
+
+