GnuCash  5.6-150-g038405b370+
Public Member Functions
python.gnucash_core.GncNumeric Class Reference
Inheritance diagram for python.gnucash_core.GncNumeric:
python.gnucash_core.GnuCashCoreClass

Public Member Functions

def __init__ (self, args, kargs)
 
def __lt__ (a, b)
 
def __gt__ (a, b)
 
def __le__ (a, b)
 
def __ge__ (a, b)
 
def __eq__ (a, b)
 
def __bool__ (a)
 
def __float__ (self)
 
def __int__ (self)
 
def __pos__ (a)
 
def __neg__ (a)
 
def __abs__ (a)
 
def to_fraction (self)
 
def __str__ (self)
 
- Public Member Functions inherited from python.gnucash_core.GnuCashCoreClass
def do_lookup_create_oo_instance (self, lookup_function, cls, args)
 

Detailed Description

Object used by GnuCash to store all numbers. Always consists of a
numerator and denominator.

The constants GNC_DENOM_AUTO,
GNC_HOW_RND_FLOOR, GNC_HOW_RND_CEIL, GNC_HOW_RND_TRUNC,
GNC_HOW_RND_PROMOTE, GNC_HOW_RND_ROUND_HALF_DOWN,
GNC_HOW_RND_ROUND_HALF_UP, GNC_HOW_RND_ROUND, GNC_HOW_RND_NEVER,
GNC_HOW_DENOM_EXACT, GNC_HOW_DENOM_REDUCE, GNC_HOW_DENOM_LCD,
and GNC_HOW_DENOM_FIXED are available for arithmetic
functions like GncNumeric.add

Look at gnc-numeric.h to see how to use these

Definition at line 517 of file gnucash_core.py.

Constructor & Destructor Documentation

◆ __init__()

def python.gnucash_core.GncNumeric.__init__ (   self,
  args,
  kargs 
)
Constructor that supports the following formats:
* No arguments defaulting to zero: eg. GncNumeric() == 0/1
* A integer: e.g. GncNumeric(1) == 1/1
* Numerator and denominator intager pair: eg. GncNumeric(1, 2) == 1/2
* A floating point number: e.g. GncNumeric(0.5) == 1/2
* A floating point number with defined conversion: e.g.
  GncNumeric(0.5, GNC_DENOM_AUTO,
    GNC_HOW_DENOM_FIXED | GNC_HOW_RND_NEVER) == 1/2
* A string: e.g. GncNumeric("1/2") == 1/2

Definition at line 532 of file gnucash_core.py.

532  def __init__(self, *args, **kargs):
533  """Constructor that supports the following formats:
534  * No arguments defaulting to zero: eg. GncNumeric() == 0/1
535  * A integer: e.g. GncNumeric(1) == 1/1
536  * Numerator and denominator intager pair: eg. GncNumeric(1, 2) == 1/2
537  * A floating point number: e.g. GncNumeric(0.5) == 1/2
538  * A floating point number with defined conversion: e.g.
539  GncNumeric(0.5, GNC_DENOM_AUTO,
540  GNC_HOW_DENOM_FIXED | GNC_HOW_RND_NEVER) == 1/2
541  * A string: e.g. GncNumeric("1/2") == 1/2
542  """
543  if 'instance' not in kargs:
544  kargs['instance'] = GncNumeric.__args_to_instance(args)
545  GnuCashCoreClass.__init__(self, [], **kargs)
546 

Member Function Documentation

◆ __abs__()

def python.gnucash_core.GncNumeric.__abs__ (   a)
abs(a)

Definition at line 704 of file gnucash_core.py.

704  def __abs__(a):
705  """abs(a)"""
706  return a.abs()
707 

◆ __bool__()

def python.gnucash_core.GncNumeric.__bool__ (   a)
a != 0

Definition at line 686 of file gnucash_core.py.

686  def __bool__(a):
687  """a != 0"""
688  return bool(a.num())
689 

◆ __eq__()

def python.gnucash_core.GncNumeric.__eq__ (   a,
  b 
)
a == b

Definition at line 682 of file gnucash_core.py.

682  def __eq__(a, b):
683  """a == b"""
684  return a._richcmp(b, a._eq)
685 

◆ __ge__()

def python.gnucash_core.GncNumeric.__ge__ (   a,
  b 
)
a >= b

Definition at line 678 of file gnucash_core.py.

678  def __ge__(a, b):
679  """a >= b"""
680  return a._richcmp(b, a._ge)
681 

◆ __gt__()

def python.gnucash_core.GncNumeric.__gt__ (   a,
  b 
)
a > b

Definition at line 670 of file gnucash_core.py.

670  def __gt__(a, b):
671  """a > b"""
672  return a._richcmp(b, a._gt)
673 

◆ __le__()

def python.gnucash_core.GncNumeric.__le__ (   a,
  b 
)
a <= b

Definition at line 674 of file gnucash_core.py.

674  def __le__(a, b):
675  """a <= b"""
676  return a._richcmp(b, a._le)
677 

◆ __lt__()

def python.gnucash_core.GncNumeric.__lt__ (   a,
  b 
)
a < b

Definition at line 666 of file gnucash_core.py.

666  def __lt__(a, b):
667  """a < b"""
668  return a._richcmp(b, a._lt)
669 

◆ __neg__()

def python.gnucash_core.GncNumeric.__neg__ (   a)
-a

Definition at line 700 of file gnucash_core.py.

700  def __neg__(a):
701  """-a"""
702  return a.neg()
703 

◆ __pos__()

def python.gnucash_core.GncNumeric.__pos__ (   a)
+a

Definition at line 696 of file gnucash_core.py.

696  def __pos__(a):
697  """+a"""
698  return GncNumeric(a.num(), a.denom())
699 
The primary numeric class for representing amounts and values.
Definition: gnc-numeric.hpp:60

◆ __str__()

def python.gnucash_core.GncNumeric.__str__ (   self)
Returns a human readable numeric value string as UTF8.

Definition at line 712 of file gnucash_core.py.

712  def __str__(self):
713  """Returns a human readable numeric value string as UTF8."""
714  return gnc_numeric_to_string(self.instance)
715 
gchar * gnc_numeric_to_string(gnc_numeric n)
Convert to string.

The documentation for this class was generated from the following file: