Float cells in OpenOffice documents

34 views
Skip to first unread message

Felipe Knorr Kuhn

unread,
May 13, 2009, 1:49:27 PM5/13/09
to ruby...@googlegroups.com
Hello,

I am having the same problem reported on
http://groups.google.com/group/ruby-roo/browse_thread/thread/147aa9c2e28fe475/d2bd4c25d7b51469?lnk=gst&q=float#d2bd4c25d7b51469

My OpenOffice spreadsheet is as follows

1 + 2 3
5 - -1 6
0 / 3 0

... and is being parsed as 1.0 (Float), + (String), 2.0 (Float), 3.0
(Float), etc, even though I set the cell formatting to General or
Text.

How do you guys deal with this issue?

Thanks and regards,

FK

Thomas Preymesser

unread,
May 27, 2009, 8:39:43 AM5/27/09
to ruby-roo


On May 13, 7:49 pm, Felipe Knorr Kuhn <fkn...@gmail.com> wrote:
> Hello,
>
> I am having the same problem reported onhttp://groups.google.com/group/ruby-roo/browse_thread/thread/147aa9c2...
>
> My OpenOffice spreadsheet is as follows
>
> 1       +       2       3
> 5       -       -1      6
> 0       /       3       0
>
> ... and is being parsed as 1.0 (Float), + (String), 2.0 (Float), 3.0
> (Float), etc, even though I set the cell formatting to General or
> Text.
>
> How do you guys deal with this issue?

I don't consider this an issue. For all numerical cells you get the
numerical value as a float. If you need the Fixnum value, you can
truncate or round the float value.

-Thomas

Felipe Knorr Kuhn

unread,
May 27, 2009, 9:54:00 AM5/27/09
to ruby...@googlegroups.com
Hello Thomas

Let me explain a little better :)

I'm using Roo and Watir for data driven automated tests, so I wrote a
simple script to test http://www.bmgadg.com/calculator.php

My sheet is exactly like in the previous e-mail. I interact with the
calculator as defined in the file and compare the result of the
operations with assert_equal.

Since I can't round or truncate the numbers, all my tests fail:

<3.0> expected but was <"3">.

Here's a snippet of the code. Perhaps I'm just missing something :)

@OPERAND_1 = oo.cell(line,'A')
@OPERATOR = oo.cell(line,'B')
@OPERAND_2 = oo.cell(line,'C')
@EXPECTED_RESULT = oo.cell(line,'D')

puts "#{@OPERAND_1}\t#{@OPERATOR}\t#{@OPERAND_2}\t#{@EXPECTED_RESULT}"

@ie.text_field(:name, "win").value = @OPERAND_1
@ie.button(:value, @OPERATOR).click
@ie.text_field(:name, "win").value = @OPERAND_2
@ie.button(:value, "=").click
puts @ie.text_field(:name, "win").value
assert_equal(@EXPECTED_RESULT, @ie.text_field(:name, "win").value)

Thanks and regards,
FK

2009/5/27 Thomas Preymesser <tho...@gmail.com>:

Felipe Knorr Kuhn

unread,
Jun 18, 2009, 10:25:03 AM6/18/09
to ruby...@googlegroups.com
Hello,

excuse me for bringing this up again, but I still can't find a workaround for this.

Truncating is not an option as you may want to compare float numbers.

Thanks

FK

2009/5/27 Felipe Knorr Kuhn <fkn...@gmail.com>

Rislejay

unread,
Jul 28, 2009, 2:32:26 PM7/28/09
to ruby-roo
How about using another column(s) to indicate whether or not to
truncate? It isn't an elegant solution but would give you a quick work
around with a if/else

Then do something like (t=truncate)

if oo.cell(line,'E') == 't'
@OPERAND_1 = oo.cell(line,'A').floor
else
@OPERAND_1 = oo.cell(line,'A')
end

@OPERATOR = oo.cell(line,'B')

if oo.cell(line,'F') == 't'
@OPERAND_2 = oo.cell(line,'C').floor
else
@OPERAND_2 = oo.cell(line,'C')
end

@EXPECTED_RESULT = oo.cell(line,'D')

On Jun 18, 10:25 am, Felipe Knorr Kuhn <fkn...@gmail.com> wrote:
> Hello,
>
> excuse me for bringing this up again, but I still can't find a workaround
> for this.
>
> Truncating is not an option as you may want to compare float numbers.
>
> Thanks
>
> FK
>
> 2009/5/27 Felipe Knorr Kuhn <fkn...@gmail.com>
>
> > Hello Thomas
>
> > Let me explain a little better :)
>
> > I'm using Roo and Watir for data driven automated tests, so I wrote a
> > simple script to testhttp://www.bmgadg.com/calculator.php

Thomas Preymesser

unread,
Jul 28, 2009, 3:20:09 PM7/28/09
to ruby...@googlegroups.com
Hello Felipe,

2009/5/27 Felipe Knorr Kuhn <fkn...@gmail.com>
Hello Thomas

Let me explain a little better :)

I'm using Roo and Watir for data driven automated tests, so I wrote a
simple script to test http://www.bmgadg.com/calculator.php

My sheet is exactly like in the previous e-mail. I interact with the
calculator as defined in the file and compare the result of the
operations with assert_equal.

Since I can't round or truncate the numbers, all my tests fail:

<3.0> expected but was <"3">.

Here's a snippet of the code. Perhaps I'm just missing something :)

     @OPERAND_1 = oo.cell(line,'A')
     @OPERATOR = oo.cell(line,'B')
     @OPERAND_2 = oo.cell(line,'C')
     @EXPECTED_RESULT = oo.cell(line,'D')

     puts "#{@OPERAND_1}\t#{@OPERATOR}\t#{@OPERAND_2}\t#{@EXPECTED_RESULT}"

     @ie.text_field(:name, "win").value = @OPERAND_1
     @ie.button(:value, @OPERATOR).click
     @ie.text_field(:name, "win").value = @OPERAND_2
     @ie.button(:value, "=").click
     puts @ie.text_field(:name, "win").value
     assert_equal(@EXPECTED_RESULT, @ie.text_field(:name, "win").value)

I think you have two problems:

1) you are comparing a float number with a string.
<3.0> expected but was <"3">.
    this will never be equal.
2) you should change
assert_equal(@EXPECTED_RESULT, @ie.text_field(:name, "win").value)
    into
    assert_in_delta(@EXPECTED_RESULT, @ie.text_field(:name, "win").value.to_f,0.0001)
    and everything should be fine

-Thomas



--
Thomas Preymesser
tho...@gmail.com
http://thopre.googlepages.com/
http://thopre.wordpress.com/

Samuel Goldwyn  - "I'm willing to admit that I may not always be right, but I am never wrong."
Reply all
Reply to author
Forward
0 new messages