Documentation ¶
Overview ¶
Package unitjuice provides utility functions to work with basis points of various units for precise computations, avoiding the use of floating point numbers.
Index ¶
- func ToBasis(valueMajorUnit float64, u Unit) (int64, error)
- func ToMajor[T Integer](valueBasisPoints T, u Unit) float64
- type Integer
- type Unit
- func (u Unit) FromInt(valueBasisPoints int) float64
- func (u Unit) FromInt32(valueBasisPoints int32) float64
- func (u Unit) FromInt64(valueBasisPoints int64) float64
- func (u Unit) ToBasisInt(valueMajorUnit float64) (int, error)
- func (u Unit) ToBasisInt32(valueMajorUnit float64) (int32, error)
- func (u Unit) ToBasisInt64(valueMajorUnit float64) (int64, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Unit ¶ added in v1.23.1
type Unit int64
Unit represents a conversion rate between a unit and its basis points.
const ( // Represents a ratio of 1000000000 (one billionths) of a unit to one unit. X1000000000 Unit = 1000000000 // Represents a ratio of 100000000 (one hundred millionths) of a unit to one unit. X100000000 Unit = 100000000 // Represents a ratio of 10000000 (ten millionths) of a unit to one unit. X10000000 Unit = 10000000 // Represents a ratio of 1000000 (millionths) of a unit to one unit. X1000000 Unit = 1000000 // Represents a ratio of 100000 (thousandths) of a unit to one unit. X100000 Unit = 100000 // Represents a ratio of 10000 (thousandths) of a unit to one unit. X10000 Unit = 10000 // Represents a ratio of 1000 (thousandths) of a unit to one unit. X1000 Unit = 1000 // Represents a ratio of 100 (hundredths) of a unit to one unit. X100 Unit = 100 // Represents a ratio of 10 (tenths) of a unit to one unit. X10 Unit = 10 // Represents a ratio of 1 (unit) of a unit to one unit. X1 Unit = 1 )
Predefined conversion rates (Units).
func (Unit) FromInt ¶ added in v1.23.1
FromInt converts an int value in basis points to the major unit.
- valueBasisPoints: The quantity in basis points to be converted.
func (Unit) FromInt32 ¶ added in v1.23.1
FromInt32 converts an int32 value in basis points to the major unit.
- valueBasisPoints: The quantity in basis points to be converted.
func (Unit) FromInt64 ¶ added in v1.23.1
FromInt64 converts an int64 value in basis points to the major unit.
- valueBasisPoints: The quantity in basis points to be converted.
func (Unit) ToBasisInt ¶ added in v1.23.1
ToBasisInt converts a float64 value from the major unit back to basis points.
- valueMajorUnit: The quantity in the major unit to be converted.
func (Unit) ToBasisInt32 ¶ added in v1.23.1
ToBasisInt32 converts a float64 value from the major unit back to basis points.
- valueMajorUnit: The quantity in the major unit to be converted.
Click to show internal directories.
Click to hide internal directories.