# How to use friction to bring object to a stop in a simple 2D platformer?

I'm coding the physics for a little platformer I'm making but I'm not sure how to design a friction calculation that does what I expect. When running along a platform I want the player's character to pick up speed but be prevented from going too fast due to friction counteracting their movement. Then, if they stop running I want them to continue to run for a little bit proportional to their speed (if they're going slow they should stop almost instantly).

void Update(V2!float forces, Elapsed time){
position += (velocity * time.deltaS);
forces -= 0.5 * velocity^3; //friction???
velocity += (forces * time.deltaS);
}


The forces variable contains anything accelerating the object such as gravity, or acceleration from the player hitting a directional key, etc. What keeps happening is that whatever I try to plug in as friction doesn't bring the object its moving to a nice clean stop. It will look like it's stopped but then move a pixel or two after that because its velocity, while very small, doesn't hit zero for several seconds.

I can fix this with a bunch of conditional statements, but if there's a simple solution I'd much rather do that!