numbers

package
v4.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: AGPL-3.0 Imports: 0 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package numbers provides numeric utility functions for rounding, scaling, and yield adjustment calculations.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func RoundToDecimalPlaces

func RoundToDecimalPlaces(value float32, precision uint8) float32

RoundToDecimalPlaces rounds a float32 value to the specified number of decimal places.

Example
package main

import (
	"fmt"

	"github.com/verygoodsoftwarenotvirus/platform/v4/numbers"
)

func main() {
	result := numbers.RoundToDecimalPlaces(3.14159, 2)
	fmt.Println(result)
}
Output:
3.14

func Scale

func Scale(value, factor float32, precision ...uint8) float32

Scale multiplies a value by a scaling factor and rounds to the specified precision (default: 2). Useful for scaling quantities by a factor. For example, Scale(2.5, 2.0) would return 5.0 (doubling the quantity).

Example
package main

import (
	"fmt"

	"github.com/verygoodsoftwarenotvirus/platform/v4/numbers"
)

func main() {
	// Double a quantity of 2.5
	result := numbers.Scale(2.5, 2.0)
	fmt.Println(result)
}
Output:
5

func ScaleToYield

func ScaleToYield(originalValue float32, originalYield, desiredYield int, precision ...uint8) float32

ScaleToYield scales a quantity from an original yield to a desired yield. The optional precision parameter specifies the number of decimal places to round to (default: 2). For example, ScaleToYield(2.0, 4, 6) returns 3.0 (scaling from 4 units to 6).

Example
package main

import (
	"fmt"

	"github.com/verygoodsoftwarenotvirus/platform/v4/numbers"
)

func main() {
	// Scale from 4 servings to 6 servings
	result := numbers.ScaleToYield(2.0, 4, 6)
	fmt.Println(result)
}
Output:
3

Types

This section is empty.

Jump to

Keyboard shortcuts

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