AddCommas adds commas after every 3 characters from right to left. NOTE: This function is a quick hack, it doesn't work with decimal points, and may have a bunch of other problems.
(s string)
| 139 | // NOTE: This function is a quick hack, it doesn't work with decimal |
| 140 | // points, and may have a bunch of other problems. |
| 141 | func addCommas(s string) string { |
| 142 | rev := "" |
| 143 | n := 0 |
| 144 | for i := len(s) - 1; i >= 0; i-- { |
| 145 | rev += string(s[i]) |
| 146 | n++ |
| 147 | if n%3 == 0 { |
| 148 | rev += "," |
| 149 | } |
| 150 | } |
| 151 | s = "" |
| 152 | for i := len(rev) - 1; i >= 0; i-- { |
| 153 | s += string(rev[i]) |
| 154 | } |
| 155 | return s |
| 156 | } |