xhuman

package
v0.25.15 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: Apache-2.0 Imports: 5 Imported by: 1

README

GoKit - xhuman

Human kits for Golang development.

Installation

go get -u github.com/likexian/gokit

Importing

import (
    "github.com/likexian/gokit/xhuman"
)

Documentation

Visit the docs on GoDoc

Example

Get human string for bytes size
// print 1024 * 1024 as 1MB
stringSize := xhuman.FormatByteSize(1024 * 1024)
fmt.Println("formated bytes size is:", stringSize)
Get bytes size from human string
// get 1024 * 1024 from 1MB
byteSize, err := xhuman.ParseByteSize("1MB")
if err != nil {
    fmt.Println("original bytes size is:", byteSize)
}
Get comma split string for number
// print 123456789123456 as "123,456,789,123,456"
s := xhuman.Comma(float64(123456789123456), 0)
if err != nil {
    fmt.Println("comma number:", s)
}

License

Copyright 2012-2024 Li Kexian

Licensed under the Apache License 2.0

Donation

If this project is helpful, please share it with friends.

If you want to thank me, you can give me a cup of coffee.

Documentation

Index

Constants

View Source
const (
	B = 1 << (10 * iota)
	KB
	MB
	GB
	TB
	PB
	EB
)

Bytes unit convert

Variables

View Source
var (
	// ErrStringByteSizeInvalid is string of byte size invalid error
	ErrStringByteSizeInvalid = errors.New("xhuman: string of byte size is invalid")
)

Functions

func Author

func Author() string

Author returns package author

func Comma

func Comma(n float64, precision int) string

Comma returns number string with comma

func FormatByteSize

func FormatByteSize(n int64, precision int) string

FormatByteSize returns human string of byte size

func License

func License() string

License returns package license

func ParseByteSize

func ParseByteSize(s string) (int64, error)

ParseByteSize returns int size of string size

func Round

func Round(n float64, precision int) (r float64)

Round returns round number with precision

func Version

func Version() string

Version returns package version

Types

This section is empty.

Jump to

Keyboard shortcuts

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