numbers

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: AGPL-3.0 Imports: 0 Imported by: 0

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/v2/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 (e.g. when adjusting serving sizes). For example, Scale(2.5, 2.0) would return 5.0 (doubling the quantity).

Example
package main

import (
	"fmt"

	"github.com/verygoodsoftwarenotvirus/platform/v2/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/v2/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