Guest User

Untitled

a guest
Jan 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. >>> '{0:,}'.format(1000000)
  2. '1,000,000'
  3.  
  4. >>> import locale
  5. >>> locale.setlocale(locale.LC_ALL, '')
  6. 'en_AU.utf8'
  7. >>> locale.format('%d', 1000000, 1)
  8. '1,000,000'
  9.  
  10. >>> import locale
  11. >>> locale.setlocale(locale.LC_ALL, 'de_DE.utf-8')
  12. 'de_DE.utf-8'
  13. >>> locale.format('%d', 1000000, 1)
  14. '1.000.000'
  15.  
  16. >>> format(1123000,',d')
  17. '1,123,000'
  18.  
  19. > my_float = 123456789.123456789
  20. > "{:0,.2f}".format(my_float)
  21. '123,456,789.12'
  22.  
  23. [[fill]align][sign][#][0][width][,][.precision][type]
  24.  
  25. >>> from itertools import zip_longest
  26. >>> num = "1000000"
  27. >>> sep = "."
  28. >>> places = 3
  29. >>> args = [iter(num[::-1])] * places
  30. >>> sep.join("".join(x) for x in zip_longest(*args, fillvalue=""))[::-1]
  31. '1.000.000'
  32.  
  33. i=1234567890
  34. s=str(i)
  35. str1=""
  36. s1=[elm for elm in s]
  37. if len(s1)%3==0:
  38. for i in range(0,len(s1)-3,3):
  39. str1+=s1[i]+s1[i+1]+s1[i+2]+"."
  40. str1+=s1[i]+s1[i+1]+s1[i+2]
  41. else:
  42. rem=len(s1)%3
  43. for i in range(rem):
  44. str1+=s1[i]
  45. for i in range(rem,len(s1)-1,3):
  46. str1+="."+s1[i]+s1[i+1]+s1[i+2]
  47.  
  48. print str1
  49.  
  50. 1.234.567.890
  51.  
  52. ax=plt.gca()
  53. ax.get_xaxis().set_major_formatter(matplotlib.ticker.FuncFormatter(lambda x, loc: locale.format('%d', x, 1)))
Add Comment
Please, Sign In to add comment