Advertisement
triclops200

comma handler for decimal

Oct 26th, 2012
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. def comma(n):
  2.     istring = str(n)
  3.     split = istring.split(".")
  4.     if len(split) > 1:
  5.         return comma(int(split[0])) + "." + comma(int(split[1])) #recursive decimal handling
  6.     ostring = ""
  7.     count = 0
  8.     for i in range(len(istring)-1,-1,-1): #for(int i = len(istring); i >= 0; i--)
  9.         if count == 3:
  10.             ostring = "," + ostring
  11.             count = 0
  12.         ostring = istring[i] + ostring
  13.         count += 1
  14.     return ostring
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement