~poldi1405/go-indicators

ref: 6d07ab3d9b7db29be0dd32b12f3e53185cf1539d go-indicators/progress/calculate.go -rw-r--r-- 258 bytes
6d07ab3d — Moritz Poldrack added more spinner styles 1 year, 12 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
package progress

import "errors"

// GetPercentage returns the percentage of a part from a total.
func GetPercentage(parts, total float64) (float64, error) {
	if total == 0 {
		return 0, errors.New("division by zero")
	}

	return parts / total * 100, nil
}