String format

Hi Team, I hope all of you are doing well,

I need to transform some values with double decimals, but I don´t know how to do it, for example I have the below values:
1- 0: I need to transform in 0.00
2- 11,560,000.45: I need to keep it

Was not as easy as I thought, but here is a prototype that uses Expressions node (so you need to be at least on version 5.3 and have the extension installed / or install it if prompted)

Prototype:
decimalconversion.knwf (85.4 KB)

Formula:

if( 
    missing_to_empty(regex_extract($["no"], "\\.\\d(?!\\d)",0)) != "", $["no"] + "0",
    missing_to_empty(regex_extract($["no"], "\\.\\d(?!\\d{2})",0)) != "", $["no"],
    $["no"] + ".00"
)

Overview:

Comments:

I tried to use regex_match initially however it didn’t pick up where the string matched… when I tried the same expressions in regex_extract it actually worked… so then I engineered something by chaining the conditions searching for anything with one decimal, check if it returns missing value and if not I added a 0, then check for anything which has already two decimals and returned just the number wo modification and the last one then means that there is no decimal yet so we need to add “.00”…

1 Like