decimals: github.com/olihawkins/decimals Index | Files

package decimals

import "github.com/olihawkins/decimals"

Package decimals is a small library of functions for rounding and formatting base ten numbers. These are functions that are either missing from the standard libraries or are more convenient for presenting numbers in a human-readable format.

Index

Package Files

decimals.go

func FormatFloat Uses

func FormatFloat(x float64, precision int) string

FormatFloat converts a float64 to a formatted string. The float is rounded to the given precision and formatted using a comma separator for thousands.

func FormatInt Uses

func FormatInt(x int64, precision int) string

FormatInt converts an int64 to a formatted string. The int is rounded to the given precision and formatted using a comma separator for thousands.

func FormatThousands Uses

func FormatThousands(x int64) string

FormatThousands converts an int64 into a string formatted using a comma separator for thousands.

func RoundFloat Uses

func RoundFloat(x float64, precision int) float64

RoundFloat rounds a base ten float64 to the given decimal precision. Precision may be positive, representing the number of decimal places, or negative, representing the nearest power of ten to which the float should be rounded.

func RoundInt Uses

func RoundInt(x int64, precision int) int64

RoundInt rounds a base ten int64 to the given precision. Precision is a negative number that represents the nearest power of ten to which the integer should be rounded. It is expressed as a negative number to be consistent with the decimal precision arguments used in rounding floats. If the rounded number falls outside the minimum and maximum for int64 the minimum or maximum will be returned instead.

Package decimals imports 2 packages (graph) and is imported by 1 packages. Updated 2016-07-15. Refresh now. Tools for package owners.