percent

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2021 License: MIT Imports: 0 Imported by: 33

README

percent.go

test workflow GoDoc Go Report Card

Calculate percentage in Golang.

Install

go get github.com/dariubs/percent

Usage

// Percent - calculate what %[number1] of [number2] is.
percent.Percent(25, 200) // return 50
percent.PercentFloat(25.0, 200.0) // return 50.0

// PercentOf - calculate what percent [number1] is of [number2].
percent.PercentOf(300, 2400) // return 12.5
percent.PercentOfFloat(300.0, 2400.0) // return 12.5

// Change - calculate the percent increase/decrease from two numbers.  
percent.Change(20, 60) // return 200.0
percent.ChangeFloat(20.0, 60.0) // return 200.0

Documentation

GoDoc

License

MIT

Author

Dariush Abbasi (@dariubs )

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Change

func Change(before int, after int) float64

Change - calculate the percent increase/decrease from two numbers. ex. 60 is a 200.0% increase from 20

func ChangeFloat

func ChangeFloat(before float64, after float64) float64

ChangeFloat - calculate the percent increase/decrease from two numbers. ex. 60.0 is a 200.0% increase from 20.0

func Percent

func Percent(percent int, all int) float64

Percent - calculate what %[number1] of [number2] is. ex. 25% of 200 is 50

func PercentFloat

func PercentFloat(percent float64, all float64) float64

PercentFloat - calculate what %[number1] of [number2] is. ex. 25% of 200 is 50

func PercentOf

func PercentOf(part int, total int) float64

PercentOf - calculate what percent [number1] is of [number2]. ex. 300 is 12.5% of 2400

func PercentOfFloat

func PercentOfFloat(part float64, total float64) float64

PercentOfFloat - calculate what percent [number1] is of [number2]. ex. 300 is 12.5% of 2400

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL