Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re, strutils, terminal, random
- proc addCommas*(num: int) =
- # strfmt complains about comma?!
- let s = ($num).replace (re"(\d)(?=(\d{3})+(?!\d))", r"1,")
- let backToNum = parseInt(s.replace(","))
- let color = if num == backToNum: fgGreen else: fgRed
- stdout.setForegroundColor color, false
- echo num, " =addCommas=> ", s, " =parseInt=> ", backToNum
- randomize()
- for i in 1..100:
- addCommas(random(1000000))
Advertisement
Add Comment
Please, Sign In to add comment