// commaf is a function to format number with thousand separator
// and two decimal points
commaf is a function to format number with thousand separator
and two decimal points
// commaf is a function to format number with thousand separator // and two decimal points
func Commaf(j interface{}) string {
	v, _ := strconv.ParseFloat(fmt.Sprint(j), 64)
	buf := &bytes.Buffer{}
	if v < 0 {
		buf.Write([]byte{'-'})
		v = 0 - v
	}
	s := fmt.Sprintf("%.2f", v)
	comma := []byte{','}
	parts := strings.Split(s, ".")
	pos := 0
	if len(parts[0])%3 != 0 {
		pos += len(parts[0]) % 3
		buf.WriteString(parts[0][:pos])
		buf.Write(comma)
	}
	for ; pos < len(parts[0]); pos += 3 {
		buf.WriteString(parts[0][pos : pos+3])
		buf.Write(comma)
	}
	buf.Truncate(buf.Len() - 1)
	if len(parts) > 1 {
		buf.Write([]byte{'.'})
		buf.WriteString(parts[1])
	}
	return buf.String()
}
func Commaf ( j interface { } ) string { v , _ := strconv . ParseFloat ( fmt . Sprint ( j ) , 64 ) buf := & bytes . Buffer { } if v < 0 { buf . Write ( [ ] byte { '-' } ) v = 0 - v } s := fmt . Sprintf ( " " , v ) comma := [ ] byte { ',' } parts := strings . Split ( s , " " ) pos := 0 if len ( parts [ 0 ] ) % 3 != 0 { pos += len ( parts [ 0 ] ) % 3 buf . WriteString ( parts [ 0 ] [ : pos ] ) buf . Write ( comma ) } for ; pos < len ( parts [ 0 ] ) ; pos += 3 { buf . WriteString ( parts [ 0 ] [ pos : pos + 3 ] ) buf . Write ( comma ) } buf . Truncate ( buf . Len ( ) - 1 ) if len ( parts ) > 1 { buf . Write ( [ ] byte { '.' } ) buf . WriteString ( parts [ 1 ] ) } return buf . String ( ) }
commaf is a function to format number with thousand separator
and two decimal points
commaf is a function to format number with thousand separator and two decimal points