|
66 | 66 | subject { instance.formatted_value } |
67 | 67 |
|
68 | 68 | context "when value is a float string" do |
69 | | - let(:value) { "3.14" } |
| 69 | + let(:value) { "32400.14" } |
70 | 70 |
|
71 | | - it "is the float string" do |
72 | | - expect(subject).to eql value |
| 71 | + it "is the float string with delimiters" do |
| 72 | + expect(subject).to eql "32,400.14" |
73 | 73 | end |
74 | 74 |
|
75 | | - it "is localized" do |
| 75 | + it "is localized with delimiters" do |
76 | 76 | I18n.with_locale(:de) do |
77 | | - expect(subject).to eql "3,14" |
| 77 | + expect(subject).to eql "32.400,14" |
78 | 78 | end |
79 | 79 | end |
80 | 80 | end |
81 | 81 |
|
| 82 | + context "when value is a float string with many zeroed decimals" do |
| 83 | + let(:value) { "3.0000000000000000000000000000009" } |
| 84 | + |
| 85 | + it "is formatted as a float with a minimum precision" do |
| 86 | + expect(subject).to eql "3.0" |
| 87 | + end |
| 88 | + end |
| 89 | + |
| 90 | + context "when value is a float string with some zeroed decimals" do |
| 91 | + let(:value) { "3.000" } |
| 92 | + |
| 93 | + it "is formatted as a float with a minimum precision" do |
| 94 | + expect(subject).to eql "3.0" |
| 95 | + end |
| 96 | + end |
| 97 | + |
| 98 | + context "when value is a float string with digits after the decimal point" do |
| 99 | + let(:value) { "42.87391" } |
| 100 | + |
| 101 | + it "is formatted as a float with a precision of 3 while rounding decimal places" do |
| 102 | + expect(subject).to eql "42.874" |
| 103 | + end |
| 104 | + end |
| 105 | + |
82 | 106 | context "when value is an int string" do |
83 | | - let(:value) { "42" } |
| 107 | + let(:value) { "42312" } |
84 | 108 |
|
85 | | - it "is the int string" do |
86 | | - expect(subject).to eql value |
| 109 | + it "is the int string with delimiters" do |
| 110 | + expect(subject).to eql "42,312" |
| 111 | + end |
| 112 | + |
| 113 | + it "is localized with delimiters" do |
| 114 | + I18n.with_locale(:de) do |
| 115 | + expect(subject).to eql "42.312" |
| 116 | + end |
87 | 117 | end |
88 | 118 | end |
89 | 119 |
|
|
0 commit comments