ae_fast_decimal_formatter 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ae_fast_decimal_formatter/version.rb +1 -1
- data/lib/ae_fast_decimal_formatter.rb +12 -12
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25d8e986474fd332d72658a25693cb1147d0ff71f187b5dd39e3b1be69078bb9
|
4
|
+
data.tar.gz: c0faafa4e3be83109a3de7174e7055c226129e31cdfb83c443483c6c2973a86f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0009ff8c75044a9caafee78662242e0de482dedf0dc9aa207b6d808b7d1ee4145fde1c071cd0b2d29b76fc2f4126f8b212c4b55621f2d5ae317a8f96dd1141f3'
|
7
|
+
data.tar.gz: 2cd3523e207af1a6f0cc2946bdfbc82d8d915e2e58eb488d39fb730dd92597935958f3ba628370a3ff6d426efba1d765d36116eda16b7b387f3c54b9f2a6b32e
|
@@ -5,18 +5,18 @@ class AeFastDecimalFormatter
|
|
5
5
|
precision = 0 if precision < 0
|
6
6
|
precision = 5 if precision > 5
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
8
|
+
# We can call to_f on the input to convert variety of types to floats. This is
|
9
|
+
# faster than inspecting the type of the input and performing different logic.
|
10
|
+
# This is safe as we have a test that verifies we produce the same result for
|
11
|
+
# float as we do for BigDecimals (i.e. format_long((num * 10 ** precision).round, precision)).
|
12
|
+
#
|
13
|
+
# In order to round correct, it looks like we need the two sets of rounds. For example,
|
14
|
+
# (148.855 * 100).round.to_i -> 14885 seems incorrect, so we try,
|
15
|
+
# (148.855.round(2) * 100).to_i -> 14886 but then,
|
16
|
+
# (1234567890.12.round(2) * 100).to_i -> 123456789011 which is definitely not correct.
|
17
|
+
#
|
18
|
+
# Thus the two rounds.
|
19
|
+
format_long((number.to_f.round(precision) * 10 ** precision).round, precision)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ae_fast_decimal_formatter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AppFolio
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
84
|
- !ruby/object:Gem::Version
|
85
85
|
version: '0'
|
86
86
|
requirements: []
|
87
|
-
rubygems_version: 3.
|
87
|
+
rubygems_version: 3.0.9
|
88
88
|
signing_key:
|
89
89
|
specification_version: 4
|
90
90
|
summary: Efficiently format decimal number.
|