PrecisionCalc
xl
Precision
Get Your Numbers Right
xlpGCD
Returns the greatest common divisor of a set of integers, with up to 32,767 significant digits of precision. Same as Excel's built-in GCD function, but with high precision.
The greatest common divisor is the largest integer that divides into all of the numbers in the set without a remainder.
Syntax
xlpGCD(numlist...,,format)
numlist... | Required. The
list of numbers and/or cell ranges for which to find the greatest common
divisor. Accepts up
to 29 numlist arguments, or up to 28 if the optional format argument
is used. Ignores text that can't be evaluated to a number. Ignores blank
cells. Non-integers are truncated to an integer. Does not accept negative numbers. |
|
format | Optional.
Determines formatting options (adding thousands separators and currency
symbol, and formatting in exponential notation). Any argument that begins with the text "format:" (must include the colon at the end) is evaluated as a format argument. Each of the three format options can be used individually in separate arguments, or any number of them can be combined in the same argument. When combining multiple format options into one format argument:
Must be enclosed in double quotes ("") if included directly in an xlpGCD argument. Double quotes are not necessary if the format argument references a cell in which the format argument is entered. May be included anywhere in the series of xlpGCD arguments -- can be the first argument, or the last, or anywhere in-between. The format argument is not case sensitive. |
|
format value |
Result | |
format:thousands | Return value is formatted with thousands separators (commas in English). | |
format:currency | Return value is formatted with the local currency symbol. The currency symbol will be added either to the beginning or to the end of the result, whichever is appropriate for the locale. | |
format:exponent | Return value is formatted in exponential notation. | |
Examples of valid combination format values |
||
format:thousands,currency (recognizes thousands and currency) |
||
format: thousands - currency blah blah this
extra text is ignored (recognizes thousands and currency) |
||
format:thousandscurrency (recognizes thousands, and currency) |
||
FORMAT:THOUSANDS,CURRENCY (recognizes thousands, and currency) |
||
Format:Thousands,cUrReNcY (recognizes thousands and currency) |
||
format:thousands blah blah this extra text is ignored currency (recognizes thousands and currency) |
||
format:currency,thousands (recognizes currency and thousands) |
||
Examples of invalid combination format values | ||
format thousands,currency (missing colon (:) after "format") |
||
format = thousands,currency (missing colon (:) after "format") |
||
Example of partially valid combination format value | ||
format:thousand,currency (recognizes currency, BUT "thousands" is misspelled as "thousand") |
Remarks
xlPrecision results are returned as text that look like numbers, not as values that Excel recognizes as numbers. This is because Excel would truncate the results to 15 significant digits if it recognized them as numbers.
format:thousands, format:currency, and format:exponent are all ignored by the 25 SD edition of xlPrecision.
format:thousands and format:exponent ignored by the 35 SD edition of xlPrecision.
numlist can accept cells with both numbers and text.
numlist can accept cells with text formatted with the local currency symbol and thousands separators.
You can use the results of xlPrecision functions as the operands in other xlPrecision formulas without losing any precision, but using them as operands in Excel's arithmetic functions will truncate them to 15 significant digits.
If the return value is so large that it has more than 32,767 characters to the left of the decimal, then xlPrecision is of course unable to return a correct value and instead returns "#VALUE!". Note, that's a vastly larger number than Excel can return without xlPrecision. Excel itself can only return or recognize a number with no more than 308 digits to the left of the decimal.
Decimal symbols, thousands separators, and currency symbols are all localized. This means that an xlPrecision formula that returns "$1,234,567.89" in the USA will return "1.234.567,89 €" in Germany, "1 234 567,89 €" in France, "1 234 567.89 kr" in Estonia, and "1.234.567,89Lek" in Albania.
The 32,767 SD edition can only provide a maximum of 32,767 total characters, including all formatting characters such as decimal, leading hyphen or parentheses for negatives, and thousands separators. As a result, it can only return the maximum 32,767 significant digits when the result is an unformatted positive integer. This is due to Excel's limitation of 32,767 characters in a cell. In all cases, the 32,767 SD edition will give you as many significant digits as possible with the formatting you have chosen.
Depending on how many significant digits the edition of xlPrecision provides, the result may be too long to conveniently view. You can view the full result by right-clicking the cell and choosing Format Cells | Alignment | Wrap Text, and widening the column to the width of the screen. An easy way to view the full result without changing column widths or wrapping text is to right-click the cell, choose Copy, and then paste into Notepad or a word processor.
Examples
Formula | Description | Result | ||||||||||||||||||||
=xlpGCD(14,21) | Greatest common divisor of 14 and 21 | 7 | ||||||||||||||||||||
=xlpGCD(6,9,15) | Greatest common divisor of 6, 9, and 15 | 3 | ||||||||||||||||||||
=xlpGCD(15,6,9) | Greatest common divisor of 15, 6, and 9 | 3 | ||||||||||||||||||||
=xlpGCD(6,-9,15) | Greatest common divisor of 6, -9, and 15 | #NUM!" (-9 is negative. Compare to xlpGCD2) |
||||||||||||||||||||
=xlpGCD(6.1,9.9) | Greatest common divisor of 6.1 and 9.9, after truncating both to integers (6 and 9) | 3 (Compare to xlpGCD2) |
||||||||||||||||||||
=xlpGCD(2.5,10) | Greatest common divisor of 2.5 and 10, after truncating both to integers (2 and 10) | 2 (Compare to xlpGCD2) |
||||||||||||||||||||
=xlpGCD(2.5,10,17.5) | Greatest common divisor of 2.5, 10, and 17.5, after truncating to integers (2, 10, and 17) | 1 (Compare to xlpGCD2) |
||||||||||||||||||||
=xlpGCD(8.1,13.5) | Greatest common divisor of 8.1 and 13.5, after truncating to integers (8 and 13) | 1 (Compare to xlpGCD2) |
||||||||||||||||||||
=xlpGCD(A1:B2,30,36,42)
|
Greatest common divisor of values in cells A1:B2, and the values 30, 36, and 42 | 3 | ||||||||||||||||||||
=xlpGCD(A1:C3,"format:thousands,currency")
|
Greatest common divisor of values in cells A1:C3, ignoring text in cell B1 and ignoring blank cell (C2), and formatting with thousands separators and local currency symbol | $10,000 | ||||||||||||||||||||
=xlpGCD(A1:C3,format:thousands,currency)
|
Greatest common divisor of values in cells A1:C3, ignoring text in cell B1 and ignoring blank cell (C2), and with double quotes missing from around formatting argument |
10000
|
||||||||||||||||||||
=xlpGCD(A1:C3,A4)
|
Greatest common divisor of values in cells A1:C3 and A4, ignoring text in cell B1 and ignoring blank cell (C2), and formatting with thousands separators and local currency symbol | $10,000 | ||||||||||||||||||||
=xlpGCD(A1:C3,"format:currency",A4,5000,2000,3000)
|
Greatest common divisor of values in cells A1:C3 and A4, and of the values 5000, 2000, and 3000, ignoring text in cell B1 and ignoring blank cell (C2), and formatting with thousands separators and local currency symbol | $1,000 | ||||||||||||||||||||
=xlpGCD(A1:C3,A4,5000,2000,3000)
|
Greatest common divisor of values in cells A1:C3 and A4, and of the values 5000, 2000, and 3000, ignoring text in cell B1 and ignoring blank cell (C2), and formatting in exponential notation | 1.0E+3 |
See Also