I am not sure how to accept a decimal input to the function then calculate with token decimal.
Said the token decimal is 18 If the function wants to accept the value 123.4567, how to get the output result in 123456700000000000
I tried the following won't work because the input type already cut the decimal before it entered into the function
function chkAmt(uint _amt) view public returns(uint256){
uint256 finalAmt = amt;
return finalAmt;
}
This output 123 without the remaining number. I think the uint _amt
already ignore the decimal as it is unsigned integer.
I tried the following also failed. If I input with 123.34567
uint8 public token_decimal = 18;
function chkAmt(uint _amt) view public returns(uint256){
uint256 decfactor = 10**uint256(token_decimal);
uint256 rtnamt = _amt.mul(decfactor);
return rtnamt;
}
The output is 123000000000000000000 which is not right.
What is the correct way to input 123.4567 and get the output to 123456700000000000000???