I didn't get a chance to run your entire program to see but with just a
look...

val[count].to_i

Takes the value at index count and converts it to and integer and returns
that value.  So, you need to store that return:

val[count] = val[count].to_i

This will change val[count] to be an integer and will discard the original
value stored in val[count].

Hope that helps,

-andy


On Fri, Jan 30, 2009 at 5:01 AM, <[email protected]> wrote:

>
> Hello, I want to remove decimals from elements in an array, i.e.
> convert from Float to Integer and I do this:
>
> val[count].to_i
>
> but it is not working. How do I convert elements in an Array from
> Float to Integer? Any suggestions? In Ruby, that is.
> My program is pasted in below.
>
> Cheers!
>
>
>
>
> require "watir"
> require 'win32ole'
>
>
> excel = WIN32OLE::new("excel.Application")
> workbook = excel.Workbooks.Open("C:\\Programfiler\\Ruby\\FPSdata.xls")
> worksheet = workbook.WorkSheets(1)
>
> site = worksheet.Range("a2").Value.to_s
> #value = worksheet.Range("b2").Value.truncate.to_s # Bruker truncate
> for å fjerne desimaler
> val = worksheet.Range('b2:b4')['Value']
>
> test_site = site
> belop = val
>
> workbook.Close
> excel.Quit
>
> ######  Løkke for å gå gjennom arrayen tilsvarende ganger det finnes
> elementer i arrayen  ######
> count = 0
> while count < (val.length)
>
> #puts "Element:  " + count + "  Verdi:  " + val[count].truncate
>
> val[count].to_i
>
> puts val[count]
>
>
>
> ie = Watir::IE.new
> ie.goto test_site
> ie.text_field(:name, "trust-121212124878").set val[count].to_s
> ie.close();
>
> count += 1
>
> end
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Watir General" group.
To post to this group, send email to [email protected]
Before posting, please read the following guidelines: 
http://wiki.openqa.org/display/WTR/Support
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/watir-general
-~----------~----~----~----~------~----~------~--~---

Reply via email to