You're getting the values from a hash. Are they really numbers, or strings representing them?
update
After your last message, i see you get the data straight out of the database. Are the database fields (var)chars, text, blobs? -> there may be your problem.
If strings, it's obvious it may go wrong sometimes.
"We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall.