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
- Host: GitHub
- URL: https://github.com/sixarm/sixarm_ruby_numeric_percent
- Owner: SixArm
- License: other
- Created: 2012-01-13T21:25:48.000Z (over 14 years ago)
- Default Branch: main
- Last Pushed: 2023-09-15T19:28:39.000Z (almost 3 years ago)
- Last Synced: 2025-02-06T00:24:42.083Z (over 1 year ago)
- Topics: extension, gem, numeric, percent, ruby
- Language: Ruby
- Homepage: http://sixarm.com
- Size: 232 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Codeowners: CODEOWNERS
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.