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 ¶
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 ¶
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.