ALTERYX INSPIRE | Join us this May for for a multi-day virtual analytics + data science experience like no other! Register Now

Alteryx Server Discussions

Find answers, ask questions, and share expertise about Alteryx Server.

CompareDigits

jamesthomas
6 - 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!

 

Thanks in advance,

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.
CharlieS
17 - Castor
17 - Castor

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

 

 

jamesthomas
6 - Meteoroid

Thanks @CharlieS for your quick response. Can you please walk me through the below examples please?

 

CompareDigits(123574,128478,2)

 

CompareDigits(0.91234. 0.91334, 3)

 

CompareDigits(12345, 123445, 3)

CharlieS
17 - Castor
17 - Castor

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