Skip to content

Commit 584440c

Browse files
committed
Format integers without decimal places.
1 parent b3a4a7c commit 584440c

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

lib/async/service/formatting.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module Formatting
1818
# @parameter units [Array] The units to use for formatting (default: UNITS).
1919
# @returns [String] A formatted string representing the count.
2020
def format_count(value, units = UNITS)
21-
value = value.to_f
21+
value = value
2222
index = 0
2323
limit = units.size - 1
2424

@@ -27,7 +27,7 @@ def format_count(value, units = UNITS)
2727
value = value.abs
2828

2929
while value >= 1000 and index < limit
30-
value = value / 1000
30+
value = value / 1000.0
3131
index += 1
3232
end
3333

test/async/service/formatting.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88
describe Async::Service::Formatting do
99
with "#format_count" do
1010
it "formats small numbers without units" do
11-
expect(subject.format_count(0)).to be == "0.0"
12-
expect(subject.format_count(1)).to be == "1.0"
13-
expect(subject.format_count(999)).to be == "999.0"
11+
expect(subject.format_count(0)).to be == "0"
12+
expect(subject.format_count(0.0)).to be == "0.0"
13+
14+
expect(subject.format_count(1)).to be == "1"
15+
expect(subject.format_count(1.0)).to be == "1.0"
16+
17+
expect(subject.format_count(999)).to be == "999"
1418
end
1519

1620
it "formats thousands with K unit" do

0 commit comments

Comments
 (0)