Overview

Namespaces

  • NGS
    • Client
      • Exception
    • Converter
    • Patterns
  • PHP

Classes

  • BigDecimal
  • BigInt
  • ByteStream
  • LocalDate
  • Location
  • Money
  • Name
  • Point
  • S3
  • Timestamp
  • Utils
  • UUID
  • Overview
  • Namespace
  • Class
  • Tree

Class BigDecimal

Used for arbitrary length decimal numbers BigDecimal is a wrapper around primitive string type, and uses bcmath functions for arithmetic operations

Direct known subclasses

NGS\Money
Namespace: NGS
Located at BigDecimal.php
Methods summary
public
# __construct( integer|string|float|NGS\BigDecimal $value = 0, integer $scale = null )

Create a new instance with decimal value and scale

Create a new instance with decimal value and scale

Parameters

$value
integer|string|float|NGS\BigDecimal
Decimal value or BigDecimal instance
$scale
integer
$scale Decimal scale (number of decimal places), uses scale from given BigDecimal instance, or uses default scale if null
public static array
# toArray( array $items, boolean $allowNullValues = false )

Converts all elements in array to BigDecimal instance

Converts all elements in array to BigDecimal instance

Parameters

$items
array
$items Input array, each element must be a valid argument for BigDecimal constructor
$allowNullValues
boolean
$allowNullValues Allow null values in input array

Returns

array
Resulting BigDecimal array

Throws

InvalidArgumentException
If any element is null or invalid type for BigInstance constructor
public static array
# toArrayWithScale( array $items, integer $scale, boolean $allowNullValues = false )

Converts all elements in array to \NGS\BigDecimal instance

Converts all elements in array to \NGS\BigDecimal instance

Parameters

$items
array
$items Source array, each element must be a valid argument for BigDecimal constructor
$scale
integer
$scale Set non-BigDecimal values to this scale or use default if null
$allowNullValues
boolean
$allowNullValues Allow elements with null value in array

Returns

array
BigDecimal Resulting BigDecimal array

Throws

InvalidArgumentException
If any element is null or invalid type for BigInstance constructor
public static
# round( mixed $number, mixed $scale = 0 )
protected
# setScale( integer $scale )

Sets scale (number of decimal places)

Sets scale (number of decimal places)

Parameters

$scale
integer
$scale
protected
# setValue( string|integer|float $value )

Parameters

$value
string|integer|float
$value
public string
# getValue( )

Returns string representation of decimal value

Returns string representation of decimal value

Returns

string
public integer
# getScale( )

Returns decimal scale

Returns decimal scale

Returns

integer
public
# __get( mixed $name )

Magic getter for accessing private value and scale properties

Magic getter for accessing private value and scale properties

public string
# __toString( )

Returns string representation of decimal value

Returns string representation of decimal value

Returns

string
public string
# toStringWith( integer $scale )

Returns string representation of decimal value with given scale

Returns string representation of decimal value with given scale

Parameters

$scale
integer
$scale Desired scale (number of decimal places)

Returns

string
public string
# format( integer $scale )

Returns string representation of decimal value with given scale

Returns string representation of decimal value with given scale

Parameters

$scale
integer
$scale Desired scale (number of decimal places)

Returns

string
protected
# _add( NGS\BigDecimal $other )
public NGS\BigDecimal
# add( mixed $other )

Adds another BigDecimal value to this instance

Adds another BigDecimal value to this instance

Parameters

$other
mixed
$other BigDecimal Value to be added

Returns

NGS\BigDecimal
Resulting BigDecimal instance
protected
# _sub( NGS\BigDecimal $other )
public NGS\BigDecimal
# sub( mixed $other )

Subtract another BigDecimal value from this instance

Subtract another BigDecimal value from this instance

Parameters

$other
mixed
$other BigDecimal Value to be subtracted

Returns

NGS\BigDecimal
Resulting BigDecimal instance
protected
# _comp( NGS\BigDecimal $other )
public integer
# comp( mixed $other )

Compares with another BigDecimal

Compares with another BigDecimal

Parameters

$other
mixed
$other BigDecimal Value to compare with

Returns

integer
Returns 0 if the two values are equal, 1 if other value is larger, -1 otherwise.
protected
# _gt( NGS\BigDecimal $other )
public boolean
# gt( mixed $other )

Check if this value is greater than another BigDecimal

Check if this value is greater than another BigDecimal

Parameters

$other
mixed
$other BigDecimal Value to compare with

Returns

boolean
Returns true if greater than other, false otherwise
protected
# _gte( NGS\BigDecimal $other )
public boolean
# gte( mixed $other )

Check if this value is greater or equal than another BigDecimal

Check if this value is greater or equal than another BigDecimal

Parameters

$other
mixed
$other BigDecimal Value to compare with

Returns

boolean
Returns true if greater or equal than other, false otherwise
protected
# _lt( NGS\BigDecimal $other )
public boolean
# lt( mixed $other )

Check if this instance is less than another BigDecimal

Check if this instance is less than another BigDecimal

Parameters

$other
mixed
$other BigDecimal Value to compare with

Returns

boolean
Returns true if less than other, false otherwise
protected
# _lte( NGS\BigDecimal $other )
public boolean
# lte( mixed $other )

Check if this instance is less or equal than another BigDecimal

Check if this instance is less or equal than another BigDecimal

Parameters

$other
mixed
$other BigDecimal Value to compare with

Returns

boolean
Returns true if less or equal than other, false otherwise
protected
# _mul( NGS\BigDecimal $other )
public NGS\BigDecimal
# mul( mixed $other )

Multiply with another BigDecimal

Multiply with another BigDecimal

Parameters

$other
mixed
$other BigDecimal Value to multiply with

Returns

NGS\BigDecimal
Resulting BigDecimal instance
protected
# _div( NGS\BigDecimal $other )
public NGS\BigDecimal
# div( mixed $other )

Divide with another BigDecimal

Divide with another BigDecimal

Parameters

$other
mixed
$other BigDecimal Value to divide with

Returns

NGS\BigDecimal
Resulting BigDecimal instance
protected
# _mod( NGS\BigDecimal $other )
public NGS\BigDecimal
# mod( mixed $other )

Get modulus with another BigDecimal

Get modulus with another BigDecimal

Parameters

$other
mixed
$other BigDecimal Value to multiply with

Returns

NGS\BigDecimal
Resulting BigDecimal instance
protected
# _pow( NGS\BigDecimal $other )
public NGS\BigDecimal
# pow( mixed $other )

Raise this value to another BigDecimal value

Raise this value to another BigDecimal value

Parameters

$other
mixed
$other BigDecimal Value to multiply with

Returns

NGS\BigDecimal
Resulting BigDecimal instance
public NGS\BigDecimal
# sqrt( )

Square root

Square root

Returns

NGS\BigDecimal
Resulting BigDecimal instance
Constants summary
integer DEFAULT_SCALE 20
#

used for new instances, when scale isn't provided

used for new instances, when scale isn't provided

Properties summary
protected string $value
#

String representation of decimal value

String representation of decimal value

protected integer $scale
#

scale

scale

Magic properties summary
public string $value
#

String representation of decimal value

String representation of decimal value

public integer $scale
#

Decimal scale (number of decimal places)

Decimal scale (number of decimal places)

API documentation generated by ApiGen 2.8.0