Skip to content

Latest commit

 

History

History
42 lines (29 loc) · 1.23 KB

File metadata and controls

42 lines (29 loc) · 1.23 KB

bcabs

bcabs — Returns the absolute value of an arbitrary precision number.

bcabs(string $num, ?int $scale = null): string

The absolute value of a number num is the non-negative value of num without regard to its sign. Namely, num if num is a positive number, and -num if num is negative (in which case negating num makes -num positive).

For example, the absolute value of 3 is 3, and the absolute value of −3 is also 3. The absolute value of a number may be thought of as its distance from zero.

Parameters

num : The number to get the absolute value of.

scale : The number of digits after the decimal place in the result. If null, it will default to the default scale set with bcscale(), or fallback to the value of the bcmath.scale INI directive.

Return Values

The absolute value of num, as a string.

Errors/Exceptions

This function throws a ValueError in the following cases:

  • num is not a well-formed BCMath numeric string.
  • scale is outside the valid range.