Missed the Q4 Fall Release Product Update? Watch the on-demand webinar for more info on the latest in Designer 24.2, Auto Insights Magic Reports, and more!
Free Trial

Alteryx Designer Desktop Discussions

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

Round rounds up if the next digit is 5 or higher. Otherwise, rounds down

kal-tech
8 - Asteroid

 

Can I use ROUND function instead of CEIL. I believe CEIL is causing the problem here. I do not know what parameter to use in ROUND function in this case.

 

Sale (Data Type-Double)FormulaSales OutPut (DataType -VWString)Output RequiredRounding UP or Down
0.954545455ToString(CEIL(([Sale])*100)) + "%"96%95%If the 5 digit after decimal is < 5 then round down to the t number integer number. In this case it should be 95%
0.986363636ToString(CEIL(([Sale])*100)) + "%"99%99%If the 5 digit after decimal is >= 5 then round up to the  number integer number. In this case it should be 99%
4 REPLIES 4
aatalai
14 - Magnetar

@kal-tech take a look at thee workflow attached it is using the formula tool with the following expression 

 

ToString(round([Field1]*100,1))+"%"

 

Let me know how you get on

Raj
16 - Nebula

@kal-tech 
ToString(Round([sales],0.01)*100) + "%"

this should work
basically ciel is to round upwards
floor is to round downwards

hope this helps.

ChrisTX
16 - Nebula
16 - Nebula

Rounding is quite challenging.  It's not specifically an issue with Alteryx.  It's how computers represent floating point numbers.  Details below.

 

==================

 

From Alteryx Support 3/22/2022, Question on ROUND function:

 

Since this is an issue with all computers, Microsoft explains the issue for Excel users in the following article:  https://docs.microsoft.com/en-us/office/troubleshoot/excel/floating-point-arithmetic-inaccurate-resu...
 

One of their examples:  Enter the following into a new workbook:

 

A1: =(43.1-43.2)+1

Right-click cell A1, and then click Format Cells. On the Number tab, click Scientific under Category. Set the Decimal places to 15.

 

Instead of displaying 0.9, Excel displays 0.899999999999999. Because (43.1-43.2) is calculated first, -0.1 is stored temporarily and the error from storing -0.1 is introduced into the calculation.


The only way to correct this is to stick with integer math, as all base-10 integers can be represented correctly in base-2.

 

==================

 

Examples:

 

Round(1.25, 0.1)             = 1.3           Correct: rounds UP as expected

Round(1.575, 0.01)         = 1.58         Correct: rounds UP as expected

Round( 1.255, 0.01)            = 1.25     Incorrect. Should round UP to 1.26

 

==================

 

Avoid these proposed solutions, which do not always give the correct result

 

multiply by 10, use the FLOOR function, then divide by 10

   FLOOR([MyNumber] * 10) / 10

 

multiply by 100, use the FLOOR function, then divide by 100

    FLOOR([MyNumber] * 100) / 100

 

Round([MyNumber] * 10, 1) / 10

 

Round to 1 extra decimal place before rounding to the level of precision you are looking for.  To round to 1 decimal place, first round to 2 decimal places, then round to 1 decimal place.

   Round(Round([MyNumber], 0.01), 0.1)

   See https://community.alteryx.com/t5/Alteryx-Designer-Discussions/Rounding-problems/td-p/486194

 

If you want to round to an integer, you can change the data type with a SELECT tool and it will round to the nearest whole number.

If you want to round to a number of decimal places, you can use a Fixed Decimal data type and change the number after the decimal to however many places you would like

Use a SELECT tool with configuration set to data type Fixed Decimal and size 19.1

For one value in my data set, "Type:Fixed Decimal and Size 19.1" unexpectedly rounded the value UP.

All numeric values get converted to data type Double on entry to the Formula tool, so Fixed Decimal gets converted to a Double and falls afoul of the inexact representation problem.

 

==================

 

Solutions

 

round to 1 decimal place

FLOOR(Round(Round([MyNumber],  .0001),  .1) * 10 ) / 10

Recommended for Math operations:

  • round your number to 2 decimal places first
  • Or in some cases: round to 4 decimal places, then round again to 2 decimal places

 

round to 2 decimal places

FLOOR(Round(Round([MyNumber],  .0001),  .01) * 100 ) / 100

 

round to 1 decimal place

ROUND([MyNumber] + 0.00000001, 0.1)

To consistently be able to round values that end in xxx5, add a small amount to each number before rounding. The small amount should be several orders of magnitude smaller than what you round to, but several orders larger than the internal representation.

 

round to 2 decimal places

ROUND([MyNumber] + 0.00000001, 0.01)

 

==================

 

Chris

kal-tech
8 - Asteroid

aatalai, Raj  - Thank you for your time . Your solution worked.

 

 ChrisTX – Thank you very much for your detailed explanation of Round function.

Labels
Top Solution Authors