Golang : Number Format - Simple Function For Thousand Separator Using Regex
package main
import (
"fmt"
"regexp"
)
func NumberFormat(num int) string {
str := fmt.Sprintf("%d", num)
re := regexp.MustCompile("(\\d+)(\\d{3})")
for n := ""; n != str; {
n = str
str = re.ReplaceAllString(str, "$1,$2")
}
return str
}
func main() {
fmt.Println(NumberFormat(1234567890))
//will be produce : 1,234,567,890
}