GnuCash  4.11-11-ge9df8d41d2+
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 394 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 409 of file gnucash_core.py.

409  def __init__(self, *args, **kargs):
410  """Constructor that supports the following formats:
411  * No arguments defaulting to zero: eg. GncNumeric() == 0/1
412  * A integer: e.g. GncNumeric(1) == 1/1
413  * Numerator and denominator intager pair: eg. GncNumeric(1, 2) == 1/2
414  * A floating point number: e.g. GncNumeric(0.5) == 1/2
415  * A floating point number with defined conversion: e.g.
416  GncNumeric(0.5, GNC_DENOM_AUTO,
417  GNC_HOW_DENOM_FIXED | GNC_HOW_RND_NEVER) == 1/2
418  * A string: e.g. GncNumeric("1/2") == 1/2
419  """
420  if 'instance' not in kargs:
421  kargs['instance'] = GncNumeric.__args_to_instance(args)
422  GnuCashCoreClass.__init__(self, [], **kargs)
423 

Member Function Documentation

◆ __abs__()

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

Definition at line 581 of file gnucash_core.py.

581  def __abs__(a):
582  """abs(a)"""
583  return a.abs()
584 

◆ __bool__()

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

Definition at line 563 of file gnucash_core.py.

563  def __bool__(a):
564  """a != 0"""
565  return bool(a.num())
566 

◆ __eq__()

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

Definition at line 559 of file gnucash_core.py.

559  def __eq__(a, b):
560  """a == b"""
561  return a._richcmp(b, a._eq)
562 

◆ __ge__()

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

Definition at line 555 of file gnucash_core.py.

555  def __ge__(a, b):
556  """a >= b"""
557  return a._richcmp(b, a._ge)
558 

◆ __gt__()

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

Definition at line 547 of file gnucash_core.py.

547  def __gt__(a, b):
548  """a > b"""
549  return a._richcmp(b, a._gt)
550 

◆ __le__()

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

Definition at line 551 of file gnucash_core.py.

551  def __le__(a, b):
552  """a <= b"""
553  return a._richcmp(b, a._le)
554 

◆ __lt__()

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

Definition at line 543 of file gnucash_core.py.

543  def __lt__(a, b):
544  """a < b"""
545  return a._richcmp(b, a._lt)
546 

◆ __neg__()

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

Definition at line 577 of file gnucash_core.py.

577  def __neg__(a):
578  """-a"""
579  return a.neg()
580 

◆ __pos__()

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

Definition at line 573 of file gnucash_core.py.

573  def __pos__(a):
574  """+a"""
575  return GncNumeric(a.num(), a.denom())
576 
The primary numeric class for representing amounts and values.
Definition: gnc-numeric.hpp:59

◆ __str__()

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

Definition at line 589 of file gnucash_core.py.

589  def __str__(self):
590  """Returns a human readable numeric value string as UTF8."""
591  return gnc_numeric_to_string(self.instance)
592 
gchar * gnc_numeric_to_string(gnc_numeric n)
Convert to string.

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