package humanize

import (
	
	
	
	
	
)

// Comma produces a string form of the given number in base 10 with
// commas after every three orders of magnitude.
//
// e.g. Comma(834142) -> 834,142
func ( int64) string {
	 := ""

	// Min int64 can't be negated to a usable value, so it has to be special cased.
	if  == math.MinInt64 {
		return "-9,223,372,036,854,775,808"
	}

	if  < 0 {
		 = "-"
		 = 0 - 
	}

	 := []string{"", "", "", "", "", "", ""}
	 := len() - 1

	for  > 999 {
		[] = strconv.FormatInt(%1000, 10)
		switch len([]) {
		case 2:
			[] = "0" + []
		case 1:
			[] = "00" + []
		}
		 =  / 1000
		--
	}
	[] = strconv.Itoa(int())
	return  + strings.Join([:], ",")
}

// Commaf produces a string form of the given number in base 10 with
// commas after every three orders of magnitude.
//
// e.g. Commaf(834142.32) -> 834,142.32
func ( float64) string {
	 := &bytes.Buffer{}
	if  < 0 {
		.Write([]byte{'-'})
		 = 0 - 
	}

	 := []byte{','}

	 := strings.Split(strconv.FormatFloat(, 'f', -1, 64), ".")
	 := 0
	if len([0])%3 != 0 {
		 += len([0]) % 3
		.WriteString([0][:])
		.Write()
	}
	for ;  < len([0]);  += 3 {
		.WriteString([0][ : +3])
		.Write()
	}
	.Truncate(.Len() - 1)

	if len() > 1 {
		.Write([]byte{'.'})
		.WriteString([1])
	}
	return .String()
}

// CommafWithDigits works like the Commaf but limits the resulting
// string to the given number of decimal places.
//
// e.g. CommafWithDigits(834142.32, 1) -> 834,142.3
func ( float64,  int) string {
	return stripTrailingDigits(Commaf(), )
}

// BigComma produces a string form of the given big.Int in base 10
// with commas after every three orders of magnitude.
func ( *big.Int) string {
	 := ""
	if .Sign() < 0 {
		 = "-"
		.Abs()
	}

	 := big.NewInt(1000)
	 := (&big.Int{}).Set()
	,  := oom(, )
	 := make([]string, +1)
	 := len() - 1

	 := &big.Int{}
	for .Cmp() >= 0 {
		.DivMod(, , )
		[] = strconv.FormatInt(.Int64(), 10)
		switch len([]) {
		case 2:
			[] = "0" + []
		case 1:
			[] = "00" + []
		}
		--
	}
	[] = strconv.Itoa(int(.Int64()))
	return  + strings.Join([:], ",")
}