A clean interface to calculate percentages in Go: changes between values, percentage increases and partial values. Think of it as a very lightweight math library for the basic stuff. Aimed to make your code more readable and easier to understand. Inspired by mattiasgeniar/php-percentages
You can install this module with go get
command:
go get -u github.com/rorecek/percentage
import "github.com/rorecek/percentage"
// What's the percentage increase from 100 to 120?
percentage.DifferenceBetween(100, 120); // 20
// What's the absolute percentage change from 100 to 80?
percentage.AbsoluteDifferenceBetween(100, 80); // 20, not -20
// How much is 120 compared to 100?
percentage.Calculate(120, 100); // 120
// How much is 50 compared to 100?
percentage.Calculate(50, 100); // 50
// What is 20% of 200?
percentage.Of(20, 200); // 40
go test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email pavel@rorecek.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.