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
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”…
Hi everyone, first of all thanks for your answers and then I want to share my solution:
I used the “Round Double” node and below you can see the configuration.
Thanks, and regards!
Thank you for posting your solution @SergioSB.
Please note that in the latest versions of KNIME, the Round Double node has become the Number Rounder node and the UI for the config has changed.
The options to convert to string format that you have used are still present but have been “hidden” under “show advanced settings” and termed “legacy” which may be confusing to anybody trying to do something similar.
There is an example here…