An open API service indexing awesome lists of open source software.

https://github.com/sixarm/sixarm_ruby_numeric_round

SixArm.com » Ruby » Numeric #round, #floor, #ceil methods with precision
https://github.com/sixarm/sixarm_ruby_numeric_round

extensions gem numeric ruby

Last synced: over 1 year ago
JSON representation

SixArm.com » Ruby » Numeric #round, #floor, #ceil methods with precision

Awesome Lists containing this project

README

          

# SixArm.com → Ruby →
Numeric #round, #floor, #ceil methods with precision

[![Gem Version](https://badge.fury.io/rb/sixarm_ruby_numeric_round.svg)](http://badge.fury.io/rb/sixarm_ruby_numeric_round)
[![Build Status](https://travis-ci.org/SixArm/sixarm_ruby_numeric_round.png)](https://travis-ci.org/SixArm/sixarm_ruby_numeric_round)
[![Code Climate](https://api.codeclimate.com/v1/badges/1cf9d84964d38caab79a/maintainability)](https://codeclimate.com/github/SixArm/sixarm_ruby_numeric_round/maintainability)

* Git:
* Doc:
* Gem:
* Contact: Joel Parker Henderson,
* Project: [changes](CHANGES.md), [license](LICENSE.md), [contributing](CONTRIBUTING.md).

## Introduction

Simple numeric rounding methods like #round, #floor, #ceil with various precisions.

For docs go to

Want to help? We're happy to get pull requests.

## Install

### Gem

To install this gem in your shell or terminal:

gem install sixarm_ruby_numeric_round

### Gemfile

To add this gem to your Gemfile:

gem 'sixarm_ruby_numeric_round'

### Require

To require the gem in your code:

require 'sixarm_ruby_numeric_round'

## Examples

Round at a given decimal point:

4.555.ceil_at(1) #=> 4.6
4.555.floor_at(1) #=> 4.5
4.555.round_at(1) #=> 4.6
4.555.truncate_at(1) #=> 4.5

Round to a given precision:

4.555.ceil_to(0.1) #=> 4.6
4.555.floor_to(0.1) #=> 4.5
4.555.round_to(0.1) #=> 4.6
4.555.truncate_to(0.1) #=> 4.5

Conceptually, the methods for round, floor, ceil, and truncate will typically be for floating point numbers.
However, these methods can actually be for pretty much any Numeric object.
For example, one could round an Integer to the nearest kilo.

## Credit

These methods are based on the Facets library for Ruby and the developer named Trans.

The #round_at and #round_to methods are exact copies and fully compatible with Facets. The rest of the methods are very similar code and fully co-existant with Facets.

We're asking the Facets team to consider including the rest of the methods.