Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rounder

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rounder

  • 1.0.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Rounder

Gem Version Build Status

Rounds any numeric value to any nearest multiple of the chosen step.

Returns value of the same type as the input argument.

For example:

require 'rounder'

17.round_to(10)               # => 20
17.round_to(10.0)             # => 20.0

9.47.floor_to(2.5)            # => 7.5

101.ceil_to(25)               # => 125

Installation

Add this line to your application's Gemfile:

gem 'rounder'

And then execute:

bundle

Or install the gem:

gem install rounder

Usage

Require the gem:

require 'rounder'

There are three methods added to all Numeric objects: #round_to, #floor_to, and #ceil_to.

#round_to rounds to the nearest multiple of the chosen step.

54.round_to(100)  # => 100
1.4.round_to(3)   # => 0
1.5.round_to(3)   # => 3
1.6.round_to(3)   # => 3
-8.round_to(3)    # => -9

#floor_to rounds down to a multiple of the chosen step.

299.floor_to(100)  # => 200
1.81.floor_to(0.5) # => 1.5
60.floor_to(15)    # => 60
-8.floor_to(3)     # => -9

#ceil_to rounds up to a multiple of the chosen step.

201.ceil_to(100)  # => 300
1.71.ceil_to(0.5) # => 2.0
60.ceil_to(15)    # => 60
-8.ceil_to(3)     # => -6

Returned value type depends on the argument type.

21.round_to(10)     # => 20
21.round_to(10.0)   # => 20.0
21.0.round_to(10)   # => 20
21.0.round_to(10.0) # => 20.0

If you provide zero as an argument, Rounder returns unaltered value.

21.round_to(0)     # => 21
21.round_to(0.0)   # => 21.0

If negative step is provided, Rounder will use it absolute value

4.round_to(2)     # => 4
4.round_to(-2)    # => 4

RoundTo uses BigDecimal, so calculations are fairly precise

2.round_to(0.0000000006)        # => 1.9999999998

Development

After checking out the repo, run bundle install to install dependencies. Then, run rspec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

Contributing

Bug Reports and Pull Requests are welcome on GitHub Project page.

This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

Please read the CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Rounder project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the Code of Conduct.

FAQs

Package last updated on 25 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc