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

https://github.com/sixarm/sixarm_ruby_numeric_percent

SixArm.com » Ruby » Numeric#percent to calculate percentage
https://github.com/sixarm/sixarm_ruby_numeric_percent

extension gem numeric percent ruby

Last synced: over 1 year ago
JSON representation

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

Awesome Lists containing this project

README

          

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

* Doc:
* Gem:
* Repo:

## Introduction

Calculate a number as percentage with rounding.

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_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.