numutil

package
v1.2.11 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package numutil implements number helpers

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChangeByPercent

func ChangeByPercent[T Number](value T, percent float64) float64

ChangeByPercent calculates change of given number by given percent

func Drawdown added in v1.2.10

func Drawdown[T Number](high T, regular T) float64

Drawdown calculates percentage of the peak value

func Percent added in v1.2.11

func Percent[T Number](percent T, total T) float64

Percent calculates value of given <percent> from given <total>

func PercentDiff

func PercentDiff[T Number](before T, after T) float64

PercentDiff calculates percentage difference between two numbers

func PercentOf

func PercentOf[T Number](part T, total T) float64

PercentOf calculates what percent <part> of <total>

func Round added in v1.1.7

func Round[T float32 | float64](value T, precision uint) float64

Round rounds given float number to given precision (decimal digits)

Types

type Number

type Number interface {
	constraints.Integer | constraints.Float
}

Number is a constraint that covers any integer or float type

Jump to

Keyboard shortcuts

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