Add casting to routine boundary in the set direction too

The JDBC API is assumed to allow plausible conversions. Also, JavaScript has looser numeric types.

See new test, which fails before this change.