Shift Decimal
Shifts the decimal point of a numeric value. Us for turning prices into integers.
The Shift Decimal task is a purely functional task that takes two values - A and B - and outputs A * 10^B.
This task can be used to transform floating/fixed point values into integer values 2.54812 —> 254812. This task is commonly used to normalize price data into EVM-compatible formats. This task can also be used to convert a large EVM-normalized value (ex. 1500000000000000000 wei) into a human-readable format (1.5 Eth).
Definition
inputValue
: Numeric. The value to be transformed.
decimalPlaces
: Numeric. The number of decimal places to move the value. Positive values means the decimal is moved to the right.
round
: Boolean. Whether or not to round the output down to the nearest integer value.
outputName
: String. The name to be assigned to the resultant value. This is the name that will be extracted.
extracts
: See extracts. Legal values:
Timestamp
Unixtime of execution.
excludeLogs
: See exclude logs. Legal values:
TaskDefinition
The complete definition of this task at runtime.TaskOutputData
The complete set of returned values from this task.
Returned Values
This task returns one numeric value which is assigned the name given by outputName
along with any extracts.
Examples
Takes a value in Ether produced by a previous source/task. This scales the value up by 10^18 to produce a value in Wei which can be used back on-chain.
Takes the value and decimal count of an erc20 balance from a previous source/task. Scales the value down by the decimal count. Ex: 65 USDC is expressed as 65000000 USDC and USDC has a decimal count of 6. This normalizes the value to 65 for use in future tasks.
Tips for Using Shift Decimal
Use a variable extracted from a previous task (ex. a value from a price API or an on-chain value) as an
inputValue
.Only use a variable for
decimalPlaces
if it is not possible to know the translation factor before runtime.Set
round
to true if you are returning a value back on-chain and to false if you are creating a human-readable value.Ignore
extracts
unless there is a critical need for the timestamp.Typically you should ignore
excludeLogs
. It is rare that your exponentiation needs to be concealed from logs.
Last updated