From f70ba8c30836ecd2de7fbd2ea960d3afc43332b7 Mon Sep 17 00:00:00 2001 From: "Ben A. Morgan" Date: Fri, 28 Apr 2017 18:04:54 -0400 Subject: [PATCH] add support for big decimals in formating numbers --- lib/administrate/field/number.rb | 3 ++- spec/lib/fields/number_spec.rb | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/administrate/field/number.rb b/lib/administrate/field/number.rb index 95e94c36fb..79e202bd2b 100644 --- a/lib/administrate/field/number.rb +++ b/lib/administrate/field/number.rb @@ -22,7 +22,8 @@ def suffix end def decimals - default = data.is_a?(Float) ? data.to_s.split(".").last.size : 0 + _left, right = data.to_s.split(".") + default = right.nil? ? 0 : right.size options.fetch(:decimals, default) end diff --git a/spec/lib/fields/number_spec.rb b/spec/lib/fields/number_spec.rb index 29d5c2b32b..469dd3c232 100644 --- a/spec/lib/fields/number_spec.rb +++ b/spec/lib/fields/number_spec.rb @@ -58,8 +58,11 @@ end it "defaults to the precision of the decimal" do - number = Administrate::Field::Number.new(:number, 12.123456, :page) - expect(number.to_s).to eq("12.123456") + float = Administrate::Field::Number.new(:number, 12.123456, :page) + big_decimal = Administrate::Field::Number.new(:number, 0.26186536e2, :page) + + expect(float.to_s).to eq("12.123456") + expect(big_decimal.to_s).to eql("26.186536") end end