Alteryx Designer Desktop Discussions

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

ToString for decimal with round or without round?

Cy_Liu
5 - Atom

We have an case

22.33/2 = 11.165

ToString(22.33/2 ,2) = 11.16

22.67/2 = 11.335

ToString(22.67/2,2) = 11.34

 

I am confuseing.

 

 

 

2 REPLIES 2
Prometheus
12 - Quasar

If you're trying to turn the quotient into a string with two characters after the decimal but without rounding, you can use tostring(22.33/2) then use a RegEx tool's Parse output method and use this formula: (\d+\.\d{2})

ToString No Round.PNG

 

FinnCharlton
13 - Pulsar

This is pretty strange behaviour, definitely won't be trusting this function for rounding in the future:

 

image.png

 

As you can see above, the function rounds 0.155 downwards to 0.15, but rounds 0.165 upwards to 0.17.

It isn't consistent with which hundredths it rounds up or down, as 11.165 is rounded down.

 

The solution is to use the Round function before wrapping in the ToString function, like I have in the 'Round first' field in the picture. Use a formula like this:

 

ToString(round([Number],0.01))
Labels
Top Solution Authors