Error while Multiplying a u64 to u128 in Rust?

I want to multiply a u128 number with a u64 number. u64 will always be less than or equal to one. The amount is always greater than 1000000(1 million)

fn testing(amount:u128, starting_time:u64, ending_time:u64, duration:u64){
return amount*((ending_time - starting_time:u64)/duration) 

Even if the number should return something like 500,000 it always returns zero unless the ((ending_time - starting_time:u64)/duration) equals 1 then the return value always amounts.

I want to give less weightage to someone if they enter the last to the lottery. Both starting and ending times are u64 because they are in UNIX timestamps.

Example: Let's say Alice entered the lottery at time 0. Same time the lottery was started. So Alice would get full weightage for the amount she deposited let's say she deposited 30000 so she will get 30000 tickets.

Bob entered the lottery halfway through the lottery means that whatever he deposits he will get half the weightage of the deposited amount. If he deposits 30000 he will get 15000 tickets.

Division of integers truncates and yields an integer. If you divide a / b such that a < b, the result is always zero. You probably want to convert the values to floating-point before division.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.