xformatting

package
v0.0.0-...-89edfd8 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package fmtutil implements formatting for numbers as common meaningful values.

Index

Constants

View Source
const (
	K = 1024 << (10 * iota)
	M
	G
	T
	P
	E
)
View Source
const (
	Sec   = time.Second
	Min   = Sec * 60
	Hr    = Min * 60
	Day   = Hr * 24
	Week  = Day * 7
	Month = Day * 30
	Year  = Day * 365
)

Variables

This section is empty.

Functions

func FormatRoman

func FormatRoman(n int) string

FormatRoman formats an integer as Roman numerals. It panics if n < 1, much like a Roman would when confronted with the concept of zero or negative numbers.

func LongDuration

func LongDuration(n time.Duration) string

LongDuration formats a duration that is most likely much longer than what package time will handle. It uses the units seconds, minutes, hours, days, weeks, months (30 days), and years (365 days).

func ShortDuration

func ShortDuration(n time.Duration) string

HMS formats a duration as a colon-separated timestamp.

If n is less than 60 seconds, the format will be 0:ss. If n is less than 60 minutes, the format will be m:ss. Otherwise, the format will be h:mm:ss.

func ToFormattedBytes

func ToFormattedBytes(x uint64) string

func ToPrec

func ToPrec(n float64, prec int) float64

ToPrec rounds a number to the given number of total digits.

Types

type SI

type SI uint64

SI represents an integer which can format itself with SI prefixes.

Jump to

Keyboard shortcuts

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