Fix ClassCastException if the values are stored as String instead of

numeric values.

Fix for #503.

This is my first PR, so don't hesitate to provide feedback.
(I am afraid that the code style is not up to snuff)