Skip to content

Latest commit

 

History

History
74 lines (49 loc) · 1.67 KB

README.md

File metadata and controls

74 lines (49 loc) · 1.67 KB

Percent

Go Reference Go Version Go SemVer Go Report

The percent package provides a simple and easy-to-use API for working with percentages in Go.

Installation

Use go get to install this package:

go get github.com/sentenz/percent

Usage

To use the percent package in your Go program, import it like this:

import "github.com/sentenz/percent/pkg/percent"

The percent package provides functions for working with percentages, including:

  • percent.Percent()

    Calculates the percentage of a given value.

  • percent.Change()

    Calculates the percentage change between two values.

Example of Percent:

package main

import (
  "fmt"

  "github.com/sentenz/percent/pkg/percent"
)

const (
  percentage = -25
  value      = 100
)

func main() {
  result, err := percent.Percent(percentage, value)
  if err != nil {
    log.Printf("calculating percentage %v%% of %v: %v", percentage, value, err)

    return
  }

  log.Printf("%v%% of %v is %.0f\n", percentage, value, result)
}

This will output:

25% of 100 is 25

Contributing

Contributions to the percent package are welcome! If you find a bug or have a feature request, please open an issue on the GitHub repository.

License

The percent package is available under the MIT License. See the LICENSE file for more information.