There should be no need to coerce types anywhere in your code.
On the point about the floating point constants, did you find this thread? Anytime someone ends up with a negative cost value, this is the first thing to check. There’s no way costs should ever be negative, right?