cancel
Showing results for
Did you mean:

# alteryx server Discussions

## CompareDigits

Meteoroid

Hey,

Can someone explain in plain English how the comparedigits function works?

Would really appreciate, if you can provide a use case as well!

James.

---------

Below is an extract on comparedigits from the alteryx help:

CompareDigits(a,b, nNumDigits) Compares 2 numbers and determines if they are the same to the given number of digits. The comparison finds the difference between the numbers and reports A and B the same when the leading digit of the difference is NumDigits or more places to the right of the digits of the larger of A and B.

The NumDigits argument must not be null, and must be between 1 and 19, otherwise an error will result. If a non-integer is given, it is rounded to the nearest integer. (NumDigits can be between 0.5 and 19.499)

Example

CompareDigits(12345, 12444, 3)returns "True"

• because the difference is 99, and its leading digit is 3 places to the right of the leading digit of A.

CompareDigits(12345, 123445, 3)returns "False"

• because the difference is 100, and its leading digit is only 2 places to the right of the leading digit of A.

CompareDigits(12.345, 12.347, 3)returns "True"

• because the difference is 0.002, and its leading digit is 4 places to the right of the leading digit of A.

CompareDigits(12.345, 12.435, 3) returns "True"

• because the difference is 0.09, and its leading digit is 3 places to the right of the leading digit of A.

CompareDigits( .91234, .91334, 3) returns “False”

• because the difference is .001, and its leading digit is only 2 places to the right of the leading digit of A. Alteryx Certified Partner

I found the post where Ned introduced the feature. Here's what he said:

Ned wrote:

CompareDigits is the more useful function. CompareDigits(a,b,10) will return true if the 1st 10 significant digits of a and b are the same. That works equally well for comparing 1.7==1.7 as 1.7e50==1.7e50. CompareDigits is definitely the preferred way of comparing two numbers that may be anything other than integers.

https://community.alteryx.com/t5/Engine-Works-Blog/New-in-5-0-Comparing-Numbers/ba-p/1925

The logic seems to follow sequential rounding from right to left.

CompareDigits(12345,12444,3)

12345 : 12444

12350 : 12440

12400 : 12400 = true

CompareDigits(0.91234,0.91334,3)

0.91234 : 0.91334

0.91230 : 0.91330

0.91200 : 0.91300 = false

Meteoroid

CompareDigits(123574,128478,2)

CompareDigits(0.91234. 0.91334, 3)

CompareDigits(12345, 123445, 3)

Highlighted Alteryx Certified Partner

Hmmm, the first two expressions you listed break my explanation. You might have to reach out to support@alteryx.com on this one.