sizestr

package
v0.0.0-...-fdaaeef Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2016 License: MIT, MIT Imports: 3 Imported by: 0

README

sizestr

Convert 231938 into 232KB

GoDoc

Usage
go get github.com/jpillora/sizestr
sizestr.ToString(231938) //"232KB"
Significant Figures

Default is 3. Set via:

sizestr.ToStringSig(231938, 4) //"231.9KB"
Scale

Default is 1000, standard units dictates that Kilo is 1000, not 1024. Also, see this blog post. Though can set via:

sizestr.ToStringSig(231938, 4, 1024) //"226.5KB"

ToPrecision

This library also contains a Go implementation of JavaScript's Number.prototype.toPrecision

sizestr.ToPrecision(123.456, 4) //123.5
MIT License

Copyright © 2015 Jaime Pillora <dev@jpillora.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ScaleStrings = []string{"B", "KB", "MB", "GB", "TB", "PB", "XB"}

String representations of each scale

Functions

func LowerCase

func LowerCase()

func ToPrecision

func ToPrecision(n, p float64) float64

A Go implementation of JavaScript's Math.toPrecision

func ToString

func ToString(n int64) string

Converts a byte count into a byte string

func ToStringSig

func ToStringSig(n int64, sig float64) string

Converts a byte count into a byte string

func ToStringSigScale

func ToStringSigScale(n int64, sig, scale float64) string

Converts a byte count into a byte string

func ToggleCase

func ToggleCase()

ToggleCase changes the case of the scale strings ("MB" -> "mb")

func UpperCase

func UpperCase()

Types

This section is empty.

Jump to

Keyboard shortcuts

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