Skip to content

Latest commit

 

History

History
71 lines (53 loc) · 1.17 KB

README.md

File metadata and controls

71 lines (53 loc) · 1.17 KB

gotools

-- gotools is set of simple math and test helpers.

Install

go get github.com/DeyV/gotools

Usage

const (
	B  = iota // ignore first value by assigning to blank identifier
	KB = 1 << (10 * iota)
	MB
	GB
	TB
	PB
	EB
	ZB
	YB
)

func MemoryFormat

func MemoryFormat(x float64) string

MemoryFormat retun memory size (in Bytes) in verbalize form, for example 2.01MB

func NumberFormat

func NumberFormat(number float64, decimals int, decPoint, thousandsSep string) string

NumberFormat convert float or int to string (like PHP number_format() ) in local format, for example:

NumberFormat( 123456.12, 4, ",", " " )
>> 123 456,1200

Special cases are:

NumberFormat(±Inf) = formatted 0.0
NumberFormat(NaN) = formatted 0.0

func Round

func Round(x float64) int

Round convert x to int with correct math round

Special cases are:

Round(±0) = ±0
Round(±Inf) = ±0
Round(NaN) = 0

func RoundPrec

func RoundPrec(x float64, prec int) float64

RoundPrec return rounded version of x with prec precision.

Special cases are:

Round(±0) = ±0
Round(±Inf) = ±Inf
Round(NaN) = NaN