Advertisement
lcast15

Python Number to Pretty String (comma adding)

Apr 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.31 KB | None | 0 0
  1. def Num2PrettyString(Num):
  2.     String = str(Num)[::-1]
  3.     Result = ''
  4.     Count = 1
  5.     for i in String:
  6.         if Count == 3:
  7.             Result = Result + i + ','
  8.             Count = 1
  9.         else:
  10.             Result = Result + i
  11.             Count = Count + 1
  12.    
  13.     Result = Result[::-1]
  14.    
  15.     if Result.startswith(','):
  16.         Result = Result[1:]
  17.    
  18.     return Result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement