Jump to content

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

  • Love 1
Link to comment

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..

Link to comment

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).

Link to comment
  • 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_
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Read our Rules
  • Activity

    1. 2

      [Python] Code Translator 2 to 3

    2. 0

      bug gaya

    3. 5

      Fix Core Crash (unused serverside packet)

    4. 45

      Chest Drop View

    5. 0

      How to add Python 3.9 script?

    6. 15

      Metin2 Download Center - Specifications & Documentation

    7. 5

      Fix Core Crash (unused serverside packet)

    8. 45

      Chest Drop View

    9. 5

      Fix Core Crash (unused serverside packet)

  • Recently Browsing

    No registered users viewing this page.

×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.