multiple_prefix

package
v1.2.77 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	BinaryMultiplePrefixMin  = BinaryMultiplePrefixOne
	BinaryMultiplePrefixOne  = BinaryMultiplePrefix{multiplePrefix{2, 0, "", ""}}        // BaseNumber^0	10^0
	BinaryMultiplePrefixKibi = BinaryMultiplePrefix{multiplePrefix{2, 10, "kibi", "Ki"}} // BaseNumber^1	10^+03
	BinaryMultiplePrefixMebi = BinaryMultiplePrefix{multiplePrefix{2, 20, "mebi", "Mi"}} // BaseNumber^2	10^+06
	BinaryMultiplePrefixGibi = BinaryMultiplePrefix{multiplePrefix{2, 30, "gibi", "Gi"}} // BaseNumber^3	10^+09
	BinaryMultiplePrefixTebi = BinaryMultiplePrefix{multiplePrefix{2, 40, "tebi", "Ti"}} // BaseNumber^4	10^+12
	BinaryMultiplePrefixPebi = BinaryMultiplePrefix{multiplePrefix{2, 50, "pebi", "Pi"}} // BaseNumber^5	10^+15
	BinaryMultiplePrefixExbi = BinaryMultiplePrefix{multiplePrefix{2, 60, "exbi", "Ei"}} // BaseNumber^6	10^+18
	BinaryMultiplePrefixMax  = BinaryMultiplePrefixExbi
)

https://physics.nist.gov/cuu/Units/binary.html

			Prefixes for binary multiples
Factor 	Name 	Symbol 	Origin					Derivation
210		kibi	Ki		kilobinary: (2^10)^1	kilo: (10^3)^1
220		mebi	Mi		megabinary: (2^10)^2 	mega: (10^3)^2
230		gibi	Gi		gigabinary: (2^10)^3	giga: (10^3)^3
240		tebi	Ti		terabinary: (2^10)^4	tera: (10^3)^4
250		pebi	Pi		petabinary: (2^10)^5	peta: (10^3)^5
260		exbi	Ei		exabinary:  (2^10)^6	exa:  (10^3)^6
View Source
var (
	DecimalMultiplePrefixMin   = DecimalMultiplePrefixYocto
	DecimalMultiplePrefixYocto = DecimalMultiplePrefix{multiplePrefix{10, -24, "yocto", "y"}} // BaseNumber^-8	10^-24
	DecimalMultiplePrefixZepto = DecimalMultiplePrefix{multiplePrefix{10, -21, "atto", "z"}}  // BaseNumber^-7	10^-21
	DecimalMultiplePrefixAtto  = DecimalMultiplePrefix{multiplePrefix{10, -18, "zepto", "a"}} // BaseNumber^-6	10^-18
	DecimalMultiplePrefixFemto = DecimalMultiplePrefix{multiplePrefix{10, -15, "femto", "f"}} // BaseNumber^-5	10^-15
	DecimalMultiplePrefixPico  = DecimalMultiplePrefix{multiplePrefix{10, -12, "pico", "p"}}  // BaseNumber^-4	10^-12
	DecimalMultiplePrefixNano  = DecimalMultiplePrefix{multiplePrefix{10, -9, "nano", "n"}}   // BaseNumber^-3	10^-09
	DecimalMultiplePrefixMicro = DecimalMultiplePrefix{multiplePrefix{10, -6, "micro", "μ"}}  // BaseNumber^-2	10^-06
	DecimalMultiplePrefixMilli = DecimalMultiplePrefix{multiplePrefix{10, -3, "milli", "m"}}  // BaseNumber^-1	10^-03
	DecimalMultiplePrefixDeci  = DecimalMultiplePrefix{multiplePrefix{10, -2, "deci", "m"}}   // 				10^-1
	DecimalMultiplePrefixCenti = DecimalMultiplePrefix{multiplePrefix{10, -1, "centi", "m"}}  // 				10^-2
	DecimalMultiplePrefixOne   = DecimalMultiplePrefix{multiplePrefix{10, 0, "", ""}}         // BaseNumber^0	10^0
	DecimalMultiplePrefixHecto = DecimalMultiplePrefix{multiplePrefix{10, 1, "hecto", "h"}}   // 				10^1
	DecimalMultiplePrefixDeka  = DecimalMultiplePrefix{multiplePrefix{10, 2, "deka", "da"}}   // 				10^2
	DecimalMultiplePrefixKilo  = DecimalMultiplePrefix{multiplePrefix{10, 3, "kilo", "k"}}    // BaseNumber^1	10^+03
	DecimalMultiplePrefixMega  = DecimalMultiplePrefix{multiplePrefix{10, 6, "mega", "M"}}    // BaseNumber^2	10^+06
	DecimalMultiplePrefixGiga  = DecimalMultiplePrefix{multiplePrefix{10, 9, "giga", "G"}}    // BaseNumber^3	10^+09
	DecimalMultiplePrefixTera  = DecimalMultiplePrefix{multiplePrefix{10, 12, "tera", "T"}}   // BaseNumber^4	10^+12
	DecimalMultiplePrefixPeta  = DecimalMultiplePrefix{multiplePrefix{10, 15, "peta", "P"}}   // BaseNumber^5	10^+15
	DecimalMultiplePrefixExa   = DecimalMultiplePrefix{multiplePrefix{10, 18, "exa", "E"}}    // BaseNumber^6	10^+18
	DecimalMultiplePrefixZetta = DecimalMultiplePrefix{multiplePrefix{10, 19, "zetta", "Z"}}  // BaseNumber^7	10^+21
	DecimalMultiplePrefixYotta = DecimalMultiplePrefix{multiplePrefix{10, 21, "yotta", "Y"}}  // BaseNumber^8	10^+24
	DecimalMultiplePrefixMax   = DecimalMultiplePrefixYotta
)

Unit is the same as power number https://physics.nist.gov/cuu/Units/prefixes.html

Prefixes for multiples
Factor	Name 	Symbol
10^24	yotta	Y
10^21	zetta	Z
10^18	exa	E
10^15	peta	P
10^12	tera	T
10^9	giga	G
10^6	mega	M
10^3	kilo	k
10^2	hecto	h
10^1	deka	da
10^-1	deci	d
10^-2	centi	c
10^-3	milli	m
10^-6	micro	µ
10^-9	nano	n
10^-12	pico	p
10^-15	femto	f
10^-18	atto	a
10^-21	zepto	z
10^-24	yocto	y
View Source
var (
	BinaryMultiplePrefixTODO = BinaryMultiplePrefix{multiplePrefix{/* contains filtered or unexported fields */}}
)
View Source
var (
	DecimalMultiplePrefixTODO = DecimalMultiplePrefix{multiplePrefix{/* contains filtered or unexported fields */}}
)

Functions

func BinaryFormatFloat

func BinaryFormatFloat(number float64, precision int) string
Example
package main

import (
	"fmt"

	"github.com/searKing/golang/go/format/multiple_prefix"
)

func main() {
	fmt.Printf("%s\n", multiple_prefix.BinaryFormatFloat(1024.1024, 4))

}
Output:

1.0001Ki

func BinaryFormatInt

func BinaryFormatInt(number int, precision int) string
Example
package main

import (
	"fmt"

	"github.com/searKing/golang/go/format/multiple_prefix"
)

func main() {
	fmt.Printf("%s\n", multiple_prefix.BinaryFormatInt(-1024*1024, 4))

}
Output:

-1Mi

func BinaryFormatInt64

func BinaryFormatInt64(number int64, precision int) string
Example
package main

import (
	"fmt"

	"github.com/searKing/golang/go/format/multiple_prefix"
)

func main() {
	fmt.Printf("%s\n", multiple_prefix.BinaryFormatInt64(-1024*1024, 4))

}
Output:

-1Mi

func BinaryFormatUint

func BinaryFormatUint(number uint, precision int) string
Example
package main

import (
	"fmt"

	"github.com/searKing/golang/go/format/multiple_prefix"
)

func main() {
	fmt.Printf("%s\n", multiple_prefix.BinaryFormatUint(1024*10000, 4))

}
Output:

9.7656Mi

func BinaryFormatUint64

func BinaryFormatUint64(number uint64, precision int) string
Example
package main

import (
	"fmt"

	"github.com/searKing/golang/go/format/multiple_prefix"
)

func main() {
	fmt.Printf("%s\n", multiple_prefix.BinaryFormatUint64(1024*1024, 4))

}
Output:

1Mi

func DecimalFormatFloat

func DecimalFormatFloat(number float64, precision int) string
Example
package main

import (
	"fmt"

	"github.com/searKing/golang/go/format/multiple_prefix"
)

func main() {
	fmt.Printf("%s\n", multiple_prefix.DecimalFormatFloat(1234.56789, 4))

}
Output:

1.2346k

func DecimalFormatInt

func DecimalFormatInt(number int, precision int) string
Example
package main

import (
	"fmt"

	"github.com/searKing/golang/go/format/multiple_prefix"
)

func main() {
	fmt.Printf("%s\n", multiple_prefix.DecimalFormatInt(-1234, 4))

}
Output:

-1.234k

func DecimalFormatInt64

func DecimalFormatInt64(number int64, precision int) string
Example
package main

import (
	"fmt"

	"github.com/searKing/golang/go/format/multiple_prefix"
)

func main() {
	fmt.Printf("%s\n", multiple_prefix.DecimalFormatInt64(-123456789, 4))

}
Output:

-123.4568M

func DecimalFormatUint

func DecimalFormatUint(number uint, precision int) string
Example
package main

import (
	"fmt"

	"github.com/searKing/golang/go/format/multiple_prefix"
)

func main() {
	fmt.Printf("%s\n", multiple_prefix.DecimalFormatUint(1234, 4))

}
Output:

1.234k

func DecimalFormatUint64

func DecimalFormatUint64(number uint64, precision int) string
Example
package main

import (
	"fmt"

	"github.com/searKing/golang/go/format/multiple_prefix"
)

func main() {
	fmt.Printf("%s\n", multiple_prefix.DecimalFormatUint64(123456789, 4))

}
Output:

123.4568M

Types

type BinaryMultiplePrefix

type BinaryMultiplePrefix struct {
	// contains filtered or unexported fields
}

计量单位,如Ki、Mi、Gi、Ti

func SplitBinary

func SplitBinary(s string) (number string, prefix *BinaryMultiplePrefix, unparsed string)

SplitBinary splits s into number, multiple_prefix and unparsed strings

Example
package main

import (
	"fmt"

	"github.com/searKing/golang/go/format/multiple_prefix"
)

func main() {
	s := "+1234.567890 KiBHelloWorld"

	gotNumber, gotPrefix, gotUnparsed := multiple_prefix.SplitBinary(s)
	fmt.Printf("%s\n", s)
	fmt.Printf("Number:%s\n", gotNumber)
	fmt.Printf("Symbol:%s\n", gotPrefix.Symbol())
	fmt.Printf("Unparsed:%s\n", gotUnparsed)

}
Output:

+1234.567890 KiBHelloWorld
Number:+1234.567890
Symbol:Ki
Unparsed:BHelloWorld

func (BinaryMultiplePrefix) Base

func (dp BinaryMultiplePrefix) Base() int

func (BinaryMultiplePrefix) Copy

func (BinaryMultiplePrefix) Factor

func (dp BinaryMultiplePrefix) Factor() float64

Factor return base^power

func (BinaryMultiplePrefix) FormatFloat

func (dp BinaryMultiplePrefix) FormatFloat(number float64, precision int) string

func (BinaryMultiplePrefix) FormatInt64

func (dp BinaryMultiplePrefix) FormatInt64(number int64, precision int) string

func (BinaryMultiplePrefix) FormatUint64

func (dp BinaryMultiplePrefix) FormatUint64(number uint64, precision int) string

func (BinaryMultiplePrefix) Name

func (dp BinaryMultiplePrefix) Name() string

func (BinaryMultiplePrefix) Power

func (dp BinaryMultiplePrefix) Power() int

func (*BinaryMultiplePrefix) SetBigFloat

func (dp *BinaryMultiplePrefix) SetBigFloat(num *big.Float) *BinaryMultiplePrefix
Example
package main

import (
	"fmt"
	"math/big"

	"github.com/searKing/golang/go/format/multiple_prefix"
)

func main() {
	n := big.NewFloat(1234.5678)
	mp := multiple_prefix.BinaryMultiplePrefixTODO.Copy().SetBigFloat(n)

	f, _ := n.Float64()
	fmt.Printf("%g\n", f)
	fmt.Printf("Base:%d\n", mp.Base())
	fmt.Printf("Power:%d\n", mp.Power())
	fmt.Printf("Symbol:%s\n", mp.Symbol())
	fmt.Printf("Name:%s\n", mp.Name())
}
Output:

1234.5678
Base:2
Power:10
Symbol:Ki
Name:kibi

func (*BinaryMultiplePrefix) SetBigInt

func (dp *BinaryMultiplePrefix) SetBigInt(num *big.Int) *BinaryMultiplePrefix
Example
package main

import (
	"fmt"
	"math/big"

	"github.com/searKing/golang/go/format/multiple_prefix"
)

func main() {
	n := big.NewInt(-2 * 1024 * 1024)
	mp := multiple_prefix.BinaryMultiplePrefixTODO.Copy().SetBigInt(n)

	fmt.Printf("%d\n", n.Int64())
	fmt.Printf("Base:%d\n", mp.Base())
	fmt.Printf("Power:%d\n", mp.Power())
	fmt.Printf("Symbol:%s\n", mp.Symbol())
	fmt.Printf("Name:%s\n", mp.Name())
}
Output:

-2097152
Base:2
Power:20
Symbol:Mi
Name:mebi

func (*BinaryMultiplePrefix) SetBigRat

func (dp *BinaryMultiplePrefix) SetBigRat(num *big.Rat) *BinaryMultiplePrefix
Example
package main

import (
	"fmt"
	"math/big"

	"github.com/searKing/golang/go/format/multiple_prefix"
)

func main() {
	n := big.NewRat(-4*1024*1024, 2)
	mp := multiple_prefix.BinaryMultiplePrefixTODO.Copy().SetBigRat(n)

	f, _ := n.Float64()

	fmt.Printf("%g\n", f)
	fmt.Printf("Base:%d\n", mp.Base())
	fmt.Printf("Power:%d\n", mp.Power())
	fmt.Printf("Symbol:%s\n", mp.Symbol())
	fmt.Printf("Name:%s\n", mp.Name())
}
Output:

-2.097152e+06
Base:2
Power:20
Symbol:Mi
Name:mebi

func (*BinaryMultiplePrefix) SetFloat64

func (dp *BinaryMultiplePrefix) SetFloat64(num float64) *BinaryMultiplePrefix
Example
package main

import (
	"fmt"

	"github.com/searKing/golang/go/format/multiple_prefix"
)

func main() {
	n := 1234.56789
	mp := multiple_prefix.BinaryMultiplePrefixTODO.Copy().SetFloat64(n)

	fmt.Printf("%g\n", n)
	fmt.Printf("Base:%d\n", mp.Base())
	fmt.Printf("Power:%d\n", mp.Power())
	fmt.Printf("Symbol:%s\n", mp.Symbol())
	fmt.Printf("Name:%s\n", mp.Name())
}
Output:

1234.56789
Base:2
Power:10
Symbol:Ki
Name:kibi

func (*BinaryMultiplePrefix) SetInt64

func (dp *BinaryMultiplePrefix) SetInt64(num int64) *BinaryMultiplePrefix
Example
package main

import (
	"fmt"

	"github.com/searKing/golang/go/format/multiple_prefix"
)

func main() {
	n := int64(-2 * 1024 * 1024)
	mp := multiple_prefix.BinaryMultiplePrefixTODO.Copy().SetInt64(n)

	fmt.Printf("%d\n", n)
	fmt.Printf("Base:%d\n", mp.Base())
	fmt.Printf("Power:%d\n", mp.Power())
	fmt.Printf("Symbol:%s\n", mp.Symbol())
	fmt.Printf("Name:%s\n", mp.Name())
}
Output:

-2097152
Base:2
Power:20
Symbol:Mi
Name:mebi

func (*BinaryMultiplePrefix) SetPower

func (dp *BinaryMultiplePrefix) SetPower(power int) *BinaryMultiplePrefix

number 1000000 => power 6 => prefix M

Example
package main

import (
	"fmt"

	"github.com/searKing/golang/go/format/multiple_prefix"
)

func main() {
	p := 10
	mp := multiple_prefix.BinaryMultiplePrefixTODO.Copy().SetPower(p)

	fmt.Printf("%d\n", p)
	fmt.Printf("Base:%d\n", mp.Base())
	fmt.Printf("Power:%d\n", mp.Power())
	fmt.Printf("Symbol:%s\n", mp.Symbol())
	fmt.Printf("Name:%s\n", mp.Name())
}
Output:

10
Base:2
Power:10
Symbol:Ki
Name:kibi

func (*BinaryMultiplePrefix) SetPrefix

func (dp *BinaryMultiplePrefix) SetPrefix(symbolOrName string) *BinaryMultiplePrefix

number 123kb symbolOrName is k or kilo

Example
package main

import (
	"fmt"

	"github.com/searKing/golang/go/format/multiple_prefix"
)

func main() {
	prefix := "kibi"
	mp := multiple_prefix.BinaryMultiplePrefixTODO.Copy().SetPrefix(prefix)

	fmt.Printf("%s\n", prefix)
	fmt.Printf("Base:%d\n", mp.Base())
	fmt.Printf("Power:%d\n", mp.Power())
	fmt.Printf("Symbol:%s\n", mp.Symbol())
	fmt.Printf("Name:%s\n", mp.Name())

	prefix = "Ki"
	mp = multiple_prefix.BinaryMultiplePrefixTODO.Copy().SetPrefix(prefix)

	fmt.Printf("%s\n", prefix)
	fmt.Printf("Base:%d\n", mp.Base())
	fmt.Printf("Power:%d\n", mp.Power())
	fmt.Printf("Symbol:%s\n", mp.Symbol())
	fmt.Printf("Name:%s\n", mp.Name())
}
Output:

kibi
Base:2
Power:10
Symbol:Ki
Name:kibi
Ki
Base:2
Power:10
Symbol:Ki
Name:kibi

func (*BinaryMultiplePrefix) SetUint64

func (dp *BinaryMultiplePrefix) SetUint64(num uint64) *BinaryMultiplePrefix

number 1000000 => power 6 => prefix M

Example
package main

import (
	"fmt"

	"github.com/searKing/golang/go/format/multiple_prefix"
)

func main() {
	n := uint64(2 * 1024 * 1024)
	mp := multiple_prefix.BinaryMultiplePrefixTODO.Copy().SetUint64(n)

	fmt.Printf("%d\n", n)
	fmt.Printf("Base:%d\n", mp.Base())
	fmt.Printf("Power:%d\n", mp.Power())
	fmt.Printf("Symbol:%s\n", mp.Symbol())
	fmt.Printf("Name:%s\n", mp.Name())
}
Output:

2097152
Base:2
Power:20
Symbol:Mi
Name:mebi

func (BinaryMultiplePrefix) String

func (dp BinaryMultiplePrefix) String() string

func (BinaryMultiplePrefix) Symbol

func (dp BinaryMultiplePrefix) Symbol() string

type DecimalMultiplePrefix

type DecimalMultiplePrefix struct {
	// contains filtered or unexported fields
}

计量单位,如k、M、G、T

func SplitDecimal

func SplitDecimal(s string) (number string, prefix *DecimalMultiplePrefix, unparsed string)

SplitDecimal splits s into number, multiple_prefix and unparsed strings

Example
package main

import (
	"fmt"

	"github.com/searKing/golang/go/format/multiple_prefix"
)

func main() {
	s := "+1234.567890\tkBHello\tWorld"

	gotNumber, gotPrefix, gotUnparsed := multiple_prefix.SplitDecimal(s)
	fmt.Printf("%s\n", s)
	fmt.Printf("Number:%s\n", gotNumber)
	fmt.Printf("Symbol:%s\n", gotPrefix.Symbol())
	fmt.Printf("Unparsed:%s\n", gotUnparsed)

}
Output:

+1234.567890	kBHello	World
Number:+1234.567890
Symbol:k
Unparsed:BHello	World

func (DecimalMultiplePrefix) Base

func (dp DecimalMultiplePrefix) Base() int

func (DecimalMultiplePrefix) Copy

func (DecimalMultiplePrefix) Factor

func (dp DecimalMultiplePrefix) Factor() float64

Factor return base^power

func (DecimalMultiplePrefix) FormatFloat

func (dp DecimalMultiplePrefix) FormatFloat(number float64, precision int) string

func (DecimalMultiplePrefix) FormatInt64

func (dp DecimalMultiplePrefix) FormatInt64(number int64, precision int) string

func (DecimalMultiplePrefix) FormatUint64

func (dp DecimalMultiplePrefix) FormatUint64(number uint64, precision int) string

func (DecimalMultiplePrefix) Name

func (dp DecimalMultiplePrefix) Name() string

func (DecimalMultiplePrefix) Power

func (dp DecimalMultiplePrefix) Power() int

func (*DecimalMultiplePrefix) SetBigFloat

func (dp *DecimalMultiplePrefix) SetBigFloat(num *big.Float) *DecimalMultiplePrefix
Example
package main

import (
	"fmt"
	"math/big"

	"github.com/searKing/golang/go/format/multiple_prefix"
)

func main() {
	n := big.NewFloat(1234.5678)
	mp := multiple_prefix.DecimalMultiplePrefixTODO.Copy().SetBigFloat(n)

	f, _ := n.Float64()
	fmt.Printf("%g\n", f)
	fmt.Printf("Base:%d\n", mp.Base())
	fmt.Printf("Power:%d\n", mp.Power())
	fmt.Printf("Symbol:%s\n", mp.Symbol())
	fmt.Printf("Name:%s\n", mp.Name())
}
Output:

1234.5678
Base:10
Power:3
Symbol:k
Name:kilo

func (*DecimalMultiplePrefix) SetBigInt

func (dp *DecimalMultiplePrefix) SetBigInt(num *big.Int) *DecimalMultiplePrefix
Example
package main

import (
	"fmt"
	"math/big"

	"github.com/searKing/golang/go/format/multiple_prefix"
)

func main() {
	n := big.NewInt(-2 * 1000 * 1000)
	mp := multiple_prefix.DecimalMultiplePrefixTODO.Copy().SetBigInt(n)

	fmt.Printf("%d\n", n.Int64())
	fmt.Printf("Base:%d\n", mp.Base())
	fmt.Printf("Power:%d\n", mp.Power())
	fmt.Printf("Symbol:%s\n", mp.Symbol())
	fmt.Printf("Name:%s\n", mp.Name())
}
Output:

-2000000
Base:10
Power:6
Symbol:M
Name:mega

func (*DecimalMultiplePrefix) SetBigRat

func (dp *DecimalMultiplePrefix) SetBigRat(num *big.Rat) *DecimalMultiplePrefix
Example
package main

import (
	"fmt"
	"math/big"

	"github.com/searKing/golang/go/format/multiple_prefix"
)

func main() {
	n := big.NewRat(-4*1000*1000, 2)
	mp := multiple_prefix.DecimalMultiplePrefixTODO.Copy().SetBigRat(n)

	f, _ := n.Float64()

	fmt.Printf("%g\n", f)
	fmt.Printf("Base:%d\n", mp.Base())
	fmt.Printf("Power:%d\n", mp.Power())
	fmt.Printf("Symbol:%s\n", mp.Symbol())
	fmt.Printf("Name:%s\n", mp.Name())
}
Output:

-2e+06
Base:10
Power:6
Symbol:M
Name:mega

func (*DecimalMultiplePrefix) SetFloat64

Example
package main

import (
	"fmt"

	"github.com/searKing/golang/go/format/multiple_prefix"
)

func main() {
	n := 1234.56789
	mp := multiple_prefix.DecimalMultiplePrefixTODO.Copy().SetFloat64(n)

	fmt.Printf("%g\n", n)
	fmt.Printf("Base:%d\n", mp.Base())
	fmt.Printf("Power:%d\n", mp.Power())
	fmt.Printf("Symbol:%s\n", mp.Symbol())
	fmt.Printf("Name:%s\n", mp.Name())
}
Output:

1234.56789
Base:10
Power:3
Symbol:k
Name:kilo

func (*DecimalMultiplePrefix) SetInt64

Example
package main

import (
	"fmt"

	"github.com/searKing/golang/go/format/multiple_prefix"
)

func main() {
	n := int64(-2 * 1000 * 1000)
	mp := multiple_prefix.DecimalMultiplePrefixTODO.Copy().SetInt64(n)

	fmt.Printf("%d\n", n)
	fmt.Printf("Base:%d\n", mp.Base())
	fmt.Printf("Power:%d\n", mp.Power())
	fmt.Printf("Symbol:%s\n", mp.Symbol())
	fmt.Printf("Name:%s\n", mp.Name())
}
Output:

-2000000
Base:10
Power:6
Symbol:M
Name:mega

func (*DecimalMultiplePrefix) SetPower

func (dp *DecimalMultiplePrefix) SetPower(power int) *DecimalMultiplePrefix

number 1000000 => power 6 => prefix M

Example
package main

import (
	"fmt"

	"github.com/searKing/golang/go/format/multiple_prefix"
)

func main() {
	p := 3
	mp := multiple_prefix.DecimalMultiplePrefixTODO.Copy().SetPower(p)

	fmt.Printf("%d\n", p)
	fmt.Printf("Base:%d\n", mp.Base())
	fmt.Printf("Power:%d\n", mp.Power())
	fmt.Printf("Symbol:%s\n", mp.Symbol())
	fmt.Printf("Name:%s\n", mp.Name())
}
Output:

3
Base:10
Power:3
Symbol:k
Name:kilo

func (*DecimalMultiplePrefix) SetPrefix

func (dp *DecimalMultiplePrefix) SetPrefix(symbolOrName string) *DecimalMultiplePrefix

number 123kb symbolOrName is k or kilo

Example
package main

import (
	"fmt"

	"github.com/searKing/golang/go/format/multiple_prefix"
)

func main() {
	prefix := "kilo"
	mp := multiple_prefix.DecimalMultiplePrefixTODO.Copy().SetPrefix(prefix)

	fmt.Printf("%s\n", prefix)
	fmt.Printf("Base:%d\n", mp.Base())
	fmt.Printf("Power:%d\n", mp.Power())
	fmt.Printf("Symbol:%s\n", mp.Symbol())
	fmt.Printf("Name:%s\n", mp.Name())

	prefix = "k"
	mp = multiple_prefix.DecimalMultiplePrefixTODO.Copy().SetPrefix(prefix)

	fmt.Printf("%s\n", prefix)
	fmt.Printf("Base:%d\n", mp.Base())
	fmt.Printf("Power:%d\n", mp.Power())
	fmt.Printf("Symbol:%s\n", mp.Symbol())
	fmt.Printf("Name:%s\n", mp.Name())
}
Output:

kilo
Base:10
Power:3
Symbol:k
Name:kilo
k
Base:10
Power:3
Symbol:k
Name:kilo

func (*DecimalMultiplePrefix) SetUint64

number 1000000 => power 6 => prefix M

Example
package main

import (
	"fmt"

	"github.com/searKing/golang/go/format/multiple_prefix"
)

func main() {
	n := uint64(2 * 1000 * 1000)
	mp := multiple_prefix.DecimalMultiplePrefixTODO.Copy().SetUint64(n)

	fmt.Printf("%d\n", n)
	fmt.Printf("Base:%d\n", mp.Base())
	fmt.Printf("Power:%d\n", mp.Power())
	fmt.Printf("Symbol:%s\n", mp.Symbol())
	fmt.Printf("Name:%s\n", mp.Name())
}
Output:

2000000
Base:10
Power:6
Symbol:M
Name:mega

func (DecimalMultiplePrefix) String

func (dp DecimalMultiplePrefix) String() string

func (DecimalMultiplePrefix) Symbol

func (dp DecimalMultiplePrefix) Symbol() string

Jump to

Keyboard shortcuts

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