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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bfad6f29472a1ffc004d85c66182f379905f04d968324acba49ded7c3bf277c9
4
- data.tar.gz: b351216f297f3c692f42fd44e0ba917a3405e677c567fa9206d6d8f4cba936c3
3
+ metadata.gz: 25d8e986474fd332d72658a25693cb1147d0ff71f187b5dd39e3b1be69078bb9
4
+ data.tar.gz: c0faafa4e3be83109a3de7174e7055c226129e31cdfb83c443483c6c2973a86f
5
5
  SHA512:
6
- metadata.gz: d3aa9e8b0438d4f4f0dd59f286685f4d2e0954ca6b50f6aed8a02c6e819e9be2abc7886468931e2e9cf2ea0bf70525decd5364468b99b30944dc74e2e40e08b2
7
- data.tar.gz: 053b1593c4b4ed4ab05cbc1cc481361a65d9dac6b05ae1ec5f03ec06c931f712ababb7665e7cfefe6d129e2d4a9a3d7717772ca9b7502a28bed1db5e044f3946
6
+ metadata.gz: '0009ff8c75044a9caafee78662242e0de482dedf0dc9aa207b6d808b7d1ee4145fde1c071cd0b2d29b76fc2f4126f8b212c4b55621f2d5ae317a8f96dd1141f3'
7
+ data.tar.gz: 2cd3523e207af1a6f0cc2946bdfbc82d8d915e2e58eb488d39fb730dd92597935958f3ba628370a3ff6d426efba1d765d36116eda16b7b387f3c54b9f2a6b32e
@@ -1,3 +1,3 @@
1
1
  class AeFastDecimalFormatter
2
- VERSION = '2.0.0'
2
+ VERSION = '2.1.0'
3
3
  end
@@ -5,18 +5,18 @@ class AeFastDecimalFormatter
5
5
  precision = 0 if precision < 0
6
6
  precision = 5 if precision > 5
7
7
 
8
- if number.is_a?(BigDecimal)
9
- # With BigDecimal, we do not need to call round twice.
10
- format_long((number * 10 ** precision).round, precision)
11
- else
12
- # It looks like we need the two sets of rounds in order to attempt
13
- # to round floating numbers. For example,
14
- # (148.855 * 100).round -> 14885 seems incorrect, so we try,
15
- # 148.855.round(2) * 100 -> 14886 but then,
16
- # (1234567890.12.round(2) * 100).to_i -> 123456789011 which is
17
- # definitely not correct. Thus the two rounds.
18
- format_long((number.round(precision) * 10 ** precision).round, precision)
19
- end
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.0.0
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-01 00:00:00.000000000 Z
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.1.6
87
+ rubygems_version: 3.0.9
88
88
  signing_key:
89
89
  specification_version: 4
90
90
  summary: Efficiently format decimal number.