Project

precision

0.0
No commit activity in last 3 years
No release in over 3 years
Calculate the precision of a anything that can be converted into a decimal.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.5
>= 0
>= 3.0
 Project Readme

Precision

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

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:

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

Installation

gem 'precision'

Contributions