Skip to content

Instantly share code, notes, and snippets.

@leboshi
Last active October 21, 2020 22:38
Show Gist options
  • Save leboshi/e0e6302b50eaef325744087048f16924 to your computer and use it in GitHub Desktop.
Save leboshi/e0e6302b50eaef325744087048f16924 to your computer and use it in GitHub Desktop.
Roo bug: floating-point values in "0%"-formatted cells are truncated instead of rounded by :formatted_value
# frozen_string_literal: true
require 'bundler/inline'
gemfile(true) do
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem 'minitest'
gem 'roo'
end
require 'minitest/autorun'
require 'roo'
class PercentageFloatRoundingTest < Minitest::Test
def test_cell_value_rounds_percentage_formatted_value
spreadsheet = Roo::Spreadsheet.open("percentage_float_test.xlsx")
cell = spreadsheet.sheet_for('Sheet1').cells[[1, 1]]
assert_equal '57%', cell.formatted_value
end
end
@leboshi
Copy link
Author

leboshi commented Oct 21, 2020

Steps to reproduce

Download spreadsheet and script above and run; you may need to modify the file path on line 19.

Expected behavior

Test should pass. The spreadsheet contains a single cell with the value 57% as a 0%-formatted percentage. :formatted_value should return "57%".

Actual behavior

:formatted_value returns 56%.

PR incoming!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment