ajBigNumPrecision function
Description
Returns a BigNumber whose value is the value of number rounded to a precision defined in digits.
Syntax
ajBigNumPrecision(number, [digits], [rounding_mode])
Argument Name | Argument Type | Description |
---|---|---|
number (required) | String | A number in number or string format. For example, -1 or "-1". |
digits (optional) | Integer / Boolean | If it is a number, returns a number rounded to a precision of significant digits using rounding mode. If it is true then any trailing zeros of the integer part of a number are counted as significant digits, otherwise they are not. Return the original number if not specify. |
round_mode (optional) | Integer | Rounding mode to be used. Here are the supported rounding modes: 0 - Round up (away from zero) 1 - Round down (towards zero) 2 - Round ceiling (towards infinity) 3 - Round floor (towards -infinity) 4 - Round half up (towards nearest neighbour. If equidistant, rounds away from zero) 5 - Round half down (towards nearest neighbour. If equidistant, rounds towards zero) 6 - Round half even(towards nearest neighbour. If equidistant, rounds towards even neighbour) 7 - Round half ceiling (towards nearest neighbour. If equidistant, rounds towards infinity) 8 - Round half floor (towards nearest neighbour. If equidistant, rounds towards -infinity) The default value is 4 - Round half up. |
The function will return:
1) Return Value: BigNumber String
2) Return Type: Single Value
Example
Example 1
When the digits is a number, it returns the big number string with defined precision.
=ajBigNumPrecision("12345.12345",6)
The function returns 12345.12 using round_half_up as default rounding mode.
Example 2
When the digits is TRUE, it returns the number of significant digits including trailing zeros.
=ajBigNumPrecision("12345000",TRUE)
The function returns 8. If the second parameter is False, the function will return 5.
Click here to download the use case workbooks for further reference.
Error Scenarios
It will return #VALUE! when missing any required parameter or mismatch parameter type. Besides, system will raise error for below scenario(s).
Error Scenario |
---|
Number is neither a number or a string that can be converted to a number. |
Digits is not in boolean or integer data type. |
Invalid round mode, it should be between 0 and 8. |