Created
November 7, 2018 06:32
-
-
Save rizalgowandy/4900040554a88bebbc80d627dcc64983 to your computer and use it in GitHub Desktop.
Convert to Indonesia Rupiah
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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