HERAKLES Otomatik Avlı kalıcı sunucu. 19 Haziran'da açılıyor. Atius & Wizard güvencesiyle hemen kayıt ol, ön kayıt ödülleri aktif. HEMEN TIKLA!
Sizi anliyorum yanlız bölüm kurallari gereğince çalıştığına dair görsel eklenmesi gerekfinal haftamdayım serverıda uzun zamandır açmıyorum basit şeyler paylaştım zaten![]()
Python:
USE_MONEY_T_FORMAT = True
if USE_MONEY_T_FORMAT:
def FormatMoneyToK(string):
moneyString = str(string)
money = 0
if len(moneyString) > 1:
if 't' in moneyString:
money = int(moneyString.replace('t', '000000'))
elif 'T' in moneyString:
money = int(moneyString.replace('T', '000000'))
return money
The idea is good, but the code is bugged and unreadable, here're the bugs:
text = '1kks'
- ValueError: invalid literal for int() with base 10: '1000000s'
- 1000000500
- '1abcd'
If I'm the one who do this, i would do it more extendable and using a proficient way.
Python:
import re
def __ConvertMoneyText(self, text, powers=dict(k=10**3, m=10**6, b=10**9)):
"""
Format string value in thousands, millions or billions.
'1k' = 1.000
'100kk' = 100.000.000
'100m' = 100.000.000
'1b' = 1.000.000.000
'1kmb' = 1.000 (can't use multiple suffixes types)
:param text: string
:return: int
:date: 10.01.2020
:author: Vegas
"""
match = re.search(r'(\d+)({:s}+)?'.format('+|'.join(powers.keys())), text, re.I)
if match:
moneyValue, suffixName = match.groups()
moneyValue = int(moneyValue)
if not suffixName:
return moneyValue
return moneyValue * (powers[suffixName[0]] ** len(suffixName))
return 0
def OnAccept(self):
text = self.pickValueEditLine.GetText()
if text:
moneyValue = min(self.__ConvertMoneyText(text), self.maxValue)
if moneyValue:
if self.eventAccept:
self.eventAccept(moneyValue)
self.Close()
Thank you for update and ideaThe idea is good, but the code is bugged and unreadable, here're the bugs:
text = '1kks'
text = '1kk500'
- ValueError: invalid literal for int() with base 10: '1000000s'
text = '1abcd'
- 1000000500
- '1abcd'
If I'm the one who do this, i would do it more extendable and using a proficient way.
![]()
![]()
![]()
![]()
Python:import re def __ConvertMoneyText(self, text, powers=dict(k=10**3, m=10**6, b=10**9)): """ Format string value in thousands, millions or billions. '1k' = 1.000 '100kk' = 100.000.000 '100m' = 100.000.000 '1b' = 1.000.000.000 '1kmb' = 1.000 (can't use multiple suffixes types) :param text: string :return: int :date: 10.01.2020 :author: Vegas """ match = re.search(r'(\d+)({:s}+)?'.format('+|'.join(powers.keys())), text, re.I) if match: moneyValue, suffixName = match.groups() moneyValue = int(moneyValue) if not suffixName: return moneyValue return moneyValue * (powers[suffixName[0]] ** len(suffixName)) return 0 def OnAccept(self): text = self.pickValueEditLine.GetText() if text: moneyValue = min(self.__ConvertMoneyText(text), self.maxValue) if moneyValue: if self.eventAccept: self.eventAccept(moneyValue) self.Close()
Şu an konuyu görüntüleyenler (Toplam : 0, Üye: 0, Misafir: 0)
Benzer konular
- Cevaplar
- 2
- Görüntüleme
- 324
- Cevaplar
- 13
- Görüntüleme
- 1K
- Cevaplar
- 16
- Görüntüleme
- 2K

