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

https://github.com/dariubs/percent

Simple library for calculate percentages in Go.
https://github.com/dariubs/percent

calculate-percentages godoc percent percentage

Last synced: 7 months ago
JSON representation

Simple library for calculate percentages in Go.

Awesome Lists containing this project

README

          

golang percent package
======================

![test workflow](https://github.com/dariubs/percent/actions/workflows/test.yml/badge.svg) [![GoDoc](https://godoc.org/github.com/dariubs/percent?status.svg)](https://pkg.go.dev/github.com/dariubs/percent) [![Go Report Card](https://goreportcard.com/badge/github.com/dariubs/percent)](https://goreportcard.com/report/github.com/dariubs/percent)

Calculate percentage in Golang.

## Install

```shell
go get github.com/dariubs/percent
```

## Usage

```go
// 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](https://pkg.go.dev/github.com/dariubs/percent)

## License

MIT

## Author

Dariush Abbasi ([@dariubs](https://github.com/dariubs) )