Skip to content

Instantly share code, notes, and snippets.

@rizalgowandy
Created November 7, 2018 06:32
Show Gist options
  • Save rizalgowandy/4900040554a88bebbc80d627dcc64983 to your computer and use it in GitHub Desktop.
Save rizalgowandy/4900040554a88bebbc80d627dcc64983 to your computer and use it in GitHub Desktop.
Convert to Indonesia Rupiah
func ToIndonesianNumber(value int64) string {
sign := ""
if value < 0 {
sign = "-"
value = 0 - value
}
parts := []string{"", "", "", "", "", "", ""}
j := len(parts) - 1
for value > 999 {
parts[j] = strconv.FormatInt(value%1000, 10)
switch len(parts[j]) {
case 2:
parts[j] = "0" + parts[j]
case 1:
parts[j] = "00" + parts[j]
}
value = value / 1000
j--
}
parts[j] = strconv.Itoa(int(value))
return sign + strings.Join(parts[j:], ".")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment