Sha256: a7e63e76f7b2d6447043d09c77a89eb051c6f4656597a8342a478315fa31f5cc

Contents?: true

Size: 804 Bytes

Versions: 1

Compression:

Stored size: 804 Bytes

Contents

## Precision
Calculate the precision of anything that can be converted into a decimal.

```ruby
irb> Precision::Calculator.new(BigDecimal("12.12")).calculate
=> 2

irb> Precision::Calculator.new("12.1234").calculate
=> 4

irb> Precision::Calculator.new(12.123).calculate
=> 3

irb> Precision::Calculator.new(nil).calculate
=> 0

# #calculate is aliased to #to_i
irb> precision = Precision::Calculator.new(1)
irb> precision.to_i == precision.calculate
=> true
```

### Why might this be helpful?


Create the `precision` option argument using the current value of an attribute:

```ruby
<%= number_to_currency @model.n, precision: Precision::Calculator.new(@model.n).to_i %>
```

## Installation


    gem 'precision'

## Contributions

- Created by [@barelyknown](https://twitter.com/barelyknown)
- You?

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
precision-0.0.1 README.md