सरल, हल्के वजन, अभी तक विस्तृत विचार:
class Money():
def __init__(self, value):
# internally use Decimal or cents as long
self._cents = long(0)
# Now parse 'value' as needed e.g. locale-specific user-entered string, cents, Money, etc.
# Decimal helps in conversion
def as_my_app_specific_protocol(self):
# some application-specific representation
def __str__(self):
# user-friendly form, locale specific if needed
# rich comparison and basic arithmetics
def __lt__(self, other):
return self._cents < Money(other)._cents
def __add__(self, other):
return Money(self._cents + Money(other)._cents)
आप कर सकते हैं:
- लागू केवल क्या आप अपने आवेदन में की जरूरत है।
- जैसे ही आप बढ़ते हैं इसे बढ़ाएं।
- आवश्यकतानुसार आंतरिक प्रतिनिधित्व और कार्यान्वयन बदलें।
मैंने हमेशा सोचा कि मुद्रा रूपांतरण सिर्फ गुणा है। – SilentGhost
@SilentGost: हाँ और नहीं। आपको ध्यान रखना होगा कि आप * आपके मूल्यों का उपयोग कैसे करेंगे। आपने पिछले वर्ष यू $ S2000 + AR $ 6300 + € 1500 का भुगतान कब किया था और इस साल आपने यू $ S4000 + AR $ 1200 + € 500 का भुगतान किया था?ऐसी कई चीजें हैं जिन्हें आपको ध्यान में रखना है, इसलिए 'मनी' ऑब्जेक्ट को ऐतिहासिक मूल्य * और * वर्तमान मूल्य को सहेजने की आवश्यकता होगी। – voyager
पिटाफ से बचने के लिए: फ़्लोटिंग पॉइंट नंबरों का उपयोग करना। कार्यालय अंतरिक्ष देखें। –