-TuRKuaZ- 1
-TuRKuaZ-
farkmt2official 1
farkmt2official
Sevdamsın 1
Sevdamsın
mavzermete 1
mavzermete
xranzei 1
xranzei
Best Studio 1
Best Studio
Bvural41 1
Bvural41
Hikaye Ekle

Ticarette yazmalı yang sistemi

  • Konuyu başlatan Konuyu başlatan Agora Metin2
  • Başlangıç tarihi Başlangıç tarihi
  • Cevaplar Cevaplar 16
  • Görüntüleme Görüntüleme 3K
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'
text = '1kk500'
  • 1000000500
text = '1abcd'
  • '1abcd'

If I'm the one who do this, i would do it more extendable and using a proficient way.



8f9d06c2fcb7f4525c2fe219a878a09d.png
4807153bd1bb3f4e9e4b00f492054864.png

9197a657a56afcab56b8b17ce77806e1.png
2be07686886205e82d437108f547bbbd.png


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()
 
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'
text = '1kk500'
  • 1000000500
text = '1abcd'
  • '1abcd'

If I'm the one who do this, i would do it more extendable and using a proficient way.



8f9d06c2fcb7f4525c2fe219a878a09d.png
4807153bd1bb3f4e9e4b00f492054864.png

9197a657a56afcab56b8b17ce77806e1.png
2be07686886205e82d437108f547bbbd.png


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 idea
 

Şu an konuyu görüntüleyenler (Toplam : 0, Üye: 0, Misafir: 0)

Geri
Üst