After spliting a tab delimited file I have my required values in a string variable. Unfortunately the source of this file is out of my control.
Here are three exact example of what the value might hold:
- " 5.344"
- " -2.345"
- " -.977"
Notice the white space, no '0' prefixing the decimal points and the double quotes are in the string. Once I have each one in my field variable this is what I am currently doing:
int_val = BigDecimal(value_as_string.gsub(/-\./,"-0.").gsub(/\"/,'').strip).round(0).to_i
I need each one rounded to the nearest integer (.to_i rounds down). Any better ideas would be much appreciated as I can help but this this stinks!?