0

So id like to write this function in solidity but im having issues because of the integers not being accepted. s being the startin time. Lets say 1 second in unix time. x being the ending time. Lets say 1 weeks worth of unix time. Any idea on how i could put this into code and see it work?

f(x) = (0.8 / s + 1 - e)* (x - s - 1) + 0.8

The whole idea behind is that id like to calculate a fee, based on the time passed after a certain timestamp. Id like it to start at 80% and end in 0% after a week. In other words when the subtraction of the current block.timestamp - the stored one is >= than 1 weeks it becomes 0.

2

1 Answer 1

2

To represent decimal numbers, you can use integers and assumes that the first couple of digits are used as decimal places.

It is common to use 18 decimal places. When working with fixed-point numbers, it is advisable to use a math library such as prb math.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.