# Python Little Convertion Function

## Recommended Posts

Hi metin2dev today i wanna release a little function to convert in the easyest way number in pointed number string.

Ex:

From :150000000

In : 150.000.000

It's very usefull if you need to create a  new coins manage interface like that:

http://puu.sh/8WxJw.jpg

Here the full commented code:

```def splittedvalue(value):
x = value
x_list = list(x) #convert string in list

x_list.reverse() #reverse list for the right point

if len(x)%3 == 0:   #checking how many point must insert.If there is not rest,  point -1 to avoid .100.500
count_point = len(x)/3-1
else:
count_point = len(x)/3

for point in range(0,count_point):  #insert the points in the right place
x_list.insert((3*int(point+1)+point),".")

x_list.reverse()  #reverse again the list as begining
x_list = "".join(x_list) #reconvert list in string
return x_list  #finally return string value with point```

Reguards Luzzo

• 1
• Replies 4
• Created

#### Popular Days

There is already a default function in the locale.py/localeInfo.py it's called NumberToMoneyString()

There is already a default function in the locale.py/localeInfo.py it's called NumberToMoneyString()

In the default function you have a limit on the index.

This function anyway is more friendly and easier to use..

Which limit do you mean? And how is there any difference in usage?

a ) NumberToMoneyString(1234567)

b ) splittedvalue(1234567)

Moreover, due to the operations your function perform, it's most likely slower. And it only accepts strings, not ints or floats (can be quickly ammended though).

• 1 year later...
```def splittedvalue(num):
number = "{0:0,}".format(num)
return number.replace(",",".")```

print splittedvalue(1000000000000)

python 2.6+

>>> 1.000.000.000.000

Edited by Noa_

## Create an account

Register a new account

1. 2

2. 0

3. 5

4. 45

5. 0

6. 15

7. 5

8. 45

9. 5

• ### Recently Browsing

×

• Marketplace

• #### Tools

×
• Create New...