diff --git a/lib/oga/xpath/evaluator.rb b/lib/oga/xpath/evaluator.rb index 28b8204..9d1b6df 100644 --- a/lib/oga/xpath/evaluator.rb +++ b/lib/oga/xpath/evaluator.rb @@ -784,6 +784,13 @@ module Oga if convert.respond_to?(:text) return convert.text else + # If we have a number that has a zero decimal (e.g. 10.0) we want to + # get rid of that decimal. For this we'll first convert the number to + # an integer. + if convert.is_a?(Float) and convert.modulo(1).zero? + convert = convert.to_i + end + return convert.to_s end end diff --git a/spec/oga/xpath/evaluator/calls/string_spec.rb b/spec/oga/xpath/evaluator/calls/string_spec.rb index b45b543..c09e310 100644 --- a/spec/oga/xpath/evaluator/calls/string_spec.rb +++ b/spec/oga/xpath/evaluator/calls/string_spec.rb @@ -37,7 +37,7 @@ describe Oga::XPath::Evaluator do end example 'convert an integer to a string' do - @evaluator.evaluate('string(10)').should == '10.0' + @evaluator.evaluate('string(10)').should == '10' end example 'convert a float to a string' do