Add decimals to double

#1

Hi all,

I’m trying to add 3 decimals to a double (80.5 to 80.500) does anyone know how can I do this? I tried using Round Double but it only displays as many decimals as the double already has.

0 Likes

#2

Hi,

If this is for presentation and you don’t need the numeric type for calculations, then you can convert the column to string and add the 0s.

You can use something like this in Column Expressions node to do that:

dec = regexReplace(column("column1"), "^[\\d]+\\.?", "")
len = dec.length
if (len >= 3)
join(regexReplace(column("column1"), "(^[\\d]+\\.[\\d]{3}).*", "$1"))
else if (len == 2)
join(regexReplace(column("column1"), "(^[\\d]+\\.[\\d]{2}).*", "$1"), "0")
else if (len == 1)
join(regexReplace(column("column1"), "(^[\\d]+\\.[\\d]{1}).*", "$1"), "00")
else
join(column("column1"),".000")

:blush:

2 Likes