Re: 3 number and dot..



On Oct 31, 2007 3:24 PM, Abandoned <besturk@xxxxxxxxx> wrote:
On Oct 31, 10:18 pm, Paul McNett <p...@xxxxxxxxxxxx> wrote:
Abandoned wrote:
Hi..
I want to do this:
for examle:
12332321 ==> 12.332.321

How can i do?

Assuming that the dots are always in the 3rd and 7th position in the string:

def conv(s, sep="."):
l = [s[0:3], s[3:6], s[6:]]
return sep.join(l)

print conv("12332321")

--
pkm ~http://paulmcnett.com

But it's starts from the end..
print conv("12332321")
123.323.21
This is wrong it would be 12.332.321


If you're doing this for thousands separators, look at the locale module:
import locale
locale.setlocale(locale.LC_ALL, 'US') #the default C locale
doesn't do grouping
'English_United States.1252'
locale.format_string('%d', 10000, grouping=True)
'10,000'
locale.format_string('%d', 12332321, grouping=True)
'12,332,321'


I only have the US locale available on this machine, but if you use a
locale that uses "." as the thousands separator, this should work for
you.
.



Relevant Pages

  • RfD: Internationalisation
    ... 2007-06-26 Updated rationale section, LOCALE@, and minor wordsmithing ... text files that can be edited and converted to another language ... in a similar way to the ANS word C", but returns a string identifier ... We use the word locale to mean the mixture of country, language, ...
    (comp.lang.forth)
  • Re: datediff() and isdate() not working with hungarian date format (VB6)
    ... When I set in the control panel Hungry and then change the short date format ... Then Datediffand and isdate() do not work with strings. ... Dim t1 As String ... Most of the VB run-time functions are aware of your locale. ...
    (microsoft.public.vb.bugs)
  • Re: Writing Japanese or Chinese strings in a text file
    ... what locale are you running in? ... So they are right in the excel file. ... > original characters). ... web page (exactly I put with VB the string from a textarea in a chinese ...
    (microsoft.public.vb.general.discussion)
  • Re: datediff() and isdate() not working with hungarian date format (VB6)
    ... set as date format on theirs computers. ... Then Datediffand and isdate() do not work with strings. ... Dim t1 As String ... Most of the VB run-time functions are aware of your locale. ...
    (microsoft.public.vb.bugs)
  • Re: datediff() and isdate() not working with hungarian date format (VB6)
    ... Then Datediffand and isdate() do not work with strings. ... Dim t1 As String ... Most of the VB run-time functions are aware of your locale. ...
    (microsoft.public.vb.bugs)