Skip to content

SixArm/sixarm_ruby_numeric_percent

Repository files navigation

SixArm.com → Ruby →
Numeric#percent to calculate a percentage

Introduction

Calculate a number as percentage with rounding.

For docs go to http://sixarm.com/sixarm_ruby_numeric_percent/doc

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_percent

Gemfile

To add this gem to your Gemfile:

gem 'sixarm_ruby_numeric_percent'

Require

To require the gem in your code:

require 'sixarm_ruby_numeric_percent'

Examples

Percent:

require "sixarm_ruby_numeric_percent"
x=0.1234
x.percent => 12

Optional precision:

x.percent(nil) => 12 (default is to round to the closest integer)
x.percent(1) => 10
x.percent(2) => 12
x.percent(3) => 12.3
x.percent(3) => 12.34

Note that precision 1 and 2 are optimized for speed and to return integers; other precisions return floats.

About

SixArm.com » Ruby » Numeric#percent to calculate percentage

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages