We are celebrating the 10-year anniversary of the Alteryx Community! Learn more and join in on the fun here.
Start Free Trial

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

Subtraction precision between two floating point values

jpscoralick
8 - Asteroid

Hello everyone!

 

I'm working with big floating point numbers as 369814.705617128, for example (see attached file below).

jpscoralick_0-1666709325854.png

 

I need to store the subtraction [X] - [Y] (both are Double type) with two decimal places in the [Z] field (Fixed Decimal type with 19.2).
I've made three tests to check the result, as it follows:

jpscoralick_3-1666709734327.png

 

1) [X], [Y] and [Z] as Double type.

jpscoralick_5-1666709960455.png

 

2) [X] and [Y] as Double Type and [Z] as Fixed Decimal with 19.2

jpscoralick_4-1666709923399.png

 

3) [X] and [Y] converted to Fixed Decimal with 19.2 and [Z] as Fixed Decimal with 19.2

jpscoralick_6-1666709976600.png

 

So, only on the first case I'm getting the CHECK field with True.

Once I need to store [Z] with two decimal places, how can I properly get [Z] with the exact value from the subtraction [X] - [Y]?

Thanks in advance!

4 REPLIES 4
DataNath
17 - Castor
17 - Castor

Hey @jpscoralick, taken from the Alteryx help page on data types - https://help.alteryx.com/20221/designer/data-types

 

DataNath_0-1666713575471.png

 

So it looks like, although your [X] and [Y] fields are FixedDecimals, when used within a Formula tool they're converted to doubles for the calculation, hence why the level of precision doesn't match and the [CHECK] returns false, despite them visually appearing the same on the surface. We can see this when we make [X] and [Y] FixedDecimals and [Z] a double, this returns 'True' although visually it ought to be False as the level of precision is totally different:

 

DataNath_1-1666713701235.png

DataNath_2-1666713709440.png

 

Likewise, if we keep all 3 fields as FixedDecimals, but apply some rounding within the calculation itself, we can also return a 'True' value as we bring the 2 values (the result of [X]-[Y] and [Z]) to the same level of precision i.e. 2 decimal places:

 

DataNath_3-1666713800091.png

DataNath_4-1666713821649.png

gyang3
Alteryx Alumni (Retired)

@jpscoralick this article is fairly informative and should help explain why you are getting the results you are seeing in your screenshot

 

https://community.alteryx.com/t5/Alteryx-Designer-Knowledge-Base/Floating-point-numbers-are-surprisi...

 

jpscoralick
8 - Asteroid

Thanks a lot, @DataNath e @gyang3, for the quick and helpul answers!

 

So, to summarize it all: there's no useful way to represent a result as a Fixed Decimal with 100% of precision? Will I always lose some information during all the process?

DataNath
17 - Castor
17 - Castor

@jpscoralick if you want to display your result as anything less than the raw calculation of [X]-[Y] I.e. to 2 decimals as you mentioned before then by default you’ll lose the level of precision yes, as the reduction in decimal places has to either come from rounding or truncation, depending on the desired output.

Labels
Top Solution Authors