bigdecimal_places 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/bigdecimal_places.rb +3 -2
  2. metadata +2 -2
@@ -2,12 +2,13 @@ require 'bigdecimal'
2
2
 
3
3
  class BigDecimal
4
4
  def to_places(places)
5
+ negative = self < 0 ? -1 : 1
5
6
  multiplier = 10**places.to_i
6
- units = self * multiplier
7
+ units = self * multiplier * negative
7
8
  whole_units = units.round(0,BigDecimal::ROUND_DOWN).to_i
8
9
  difference = units.frac
9
10
  whole_units +=1 if difference > 0.5
10
11
  whole_units +=1 if (difference == 0.5) && (whole_units.modulo(2)==1)
11
- BigDecimal.new(whole_units.to_s) / multiplier
12
+ BigDecimal.new(whole_units.to_s) / multiplier * negative
12
13
  end
13
14
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: bigdecimal_places
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Clive Andrews
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-11-23 00:00:00 +01:00
13
+ date: 2012-03-26 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies: []
16
16