decint

package
v1.101.22 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package decint provides utility functions to parse and represent decimal values as integers with a set precision.

The functions in this package are typically used to store and retrieve small currency values without loss of precision.

Safe decimal values are limited up to 2^53 / 1e+6 = 9_007_199_254.740_992.

Index

Examples

Constants

View Source
const (

	// MaxInt is the maximum integer number that can be safely represented (2^53).
	MaxInt = 9_007_199_254_740_992

	// MaxFloat is the maximum float number that can be safely represented (2^53 / 1e+06).
	MaxFloat = 9_007_199_254.740_992
)

Variables

This section is empty.

Functions

func FloatToInt

func FloatToInt(v float64) int64

FloatToInt Converts the value to a int64 representation.

Example
Output:

123456000

func FloatToUint

func FloatToUint(v float64) uint64

FloatToUint Converts the value to a uint64 representation. Negative values are converted to zero.

Example
Output:

123456000

func IntToFloat

func IntToFloat(v int64) float64

IntToFloat Converts back the int64 representation into a float value.

Example
Output:

0.123456

func IntToString

func IntToString(v int64) string

IntToString format the int64 representation as string.

Example
Output:

0.123456

func StringToInt

func StringToInt(s string) (int64, error)

StringToInt parse the input string float value and returns the int64 representation.

Example
Output:

123456000000

func StringToUint

func StringToUint(s string) (uint64, error)

StringToUint parse the input string float value and returns the uint64 representation. Negative values are converted to zero.

Example
Output:

123456000

func UintToFloat

func UintToFloat(v uint64) float64

UintToFloat Converts back the uint64 representation into a float value.

Example
Output:

0.123456

func UintToString

func UintToString(v uint64) string

UintToString format the uint64 representation as string.

Example
Output:

0.123456

Types

This section is empty.

Jump to

Keyboard shortcuts

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