The Arithematic/cleanAndRoundNumberWithPadding extension cleans a numeric text value, rounds it to a selected number of decimal places, and pads the result to four decimal places.
This is useful when your test needs to normalize numbers that include formatting characters such as commas, currency symbols, or other non-numeric text before comparing or reusing the value.
Parameters:
-
valuerequired, the number as a text value. The value can include non-numeric characters, for example1,469.25456or$1,469.25456; -
roundingLimitrequired, the number of decimal places to round to, for example1,2, or4.
Note: The extension removes every character except digits and the decimal point before rounding. For example, $1,469.25456 is cleaned to 1469.25456.
NLP usage
Use the extension in a journey by calling Arithematic/cleanAndRoundNumberWithPadding with the execute command. Pass each value to the matching extension input using as inputName.
Note: The extension pads the decimal portion up to four digits where needed. The current source may return a JavaScript number in some branches, so trailing zeros may not always be preserved after numeric conversion.
To clean and round a formatted number:
execute "Arithematic/cleanAndRoundNumberWithPadding" using "1,469.25456" as value, "1" as roundingLimit returning $roundedValueTo clean a currency-formatted number and round it to two decimal places:
execute "Arithematic/cleanAndRoundNumberWithPadding" using "$1,469.25456" as value, "2" as roundingLimit returning $roundedValueYou can also use Virtuoso variables to make the same step reusable across different values or rounding limits:
execute "Arithematic/cleanAndRoundNumberWithPadding" using "$rawValue" as value, "$roundingLimit" as roundingLimit returning $roundedValueExample setup using variables before calling the extension:
store value "1,469.25456" in $rawValue
store value "1" in $roundingLimit
execute "Arithematic/cleanAndRoundNumberWithPadding" using "$rawValue" as value, "$roundingLimit" as roundingLimit returning $roundedValueFor example, cleaning 1,469.25456 and rounding with 1 returns:
1469.3This extension does not require any external resource.
The extension should be configured as:
- Run asynchronously: No
- Scope: Global
Limitation: This extension removes non-numeric characters before rounding. It does not preserve minus signs if they are not part of the cleaned numeric pattern, and it does not support locale-specific formats that use commas as decimal separators.
Add the extension to your Virtuoso instance
Select the domain that matches your Virtuoso account.
View source
Last updated: 22/05/2026
Resources: None
function cleanInput(input) {
return input.replace(/[^0-9.]/g, '');
}
function rounding(value, decimals) {
return Number(Math.round(value + 'e' + decimals) + 'e-' + decimals);
}
/*
let value = '1,469.25456';
let roundingLimit = '1';
*/
let cleanedValue = cleanInput(value);
let values = rounding(parseFloat(cleanedValue), Number(roundingLimit));
if (Number(values) === 0) {
const zero = values.toString().padEnd(4, "0");
console.log(values + "." + zero);
return values + "." + zero;
} else {
const extDecimals = values.toString().split(".")[1];
if (extDecimals === undefined) {
const addingZeros = "".padEnd(4, "0");
console.log(Number(values.toString().split(".")[0] + "." + addingZeros));
return Number(values.toString().split(".")[0] + "." + addingZeros);
} else {
const length = extDecimals.length;
if (length < 4) {
const addingZeros = extDecimals.padEnd(4, "0");
console.log(Number(values.toString().split(".")[0] + "." + addingZeros));
return Number(values.toString().split(".")[0] + "." + addingZeros);
} else {
console.log(values);
return values;
}
}
}
Comments
0 comments
Please sign in to leave a comment.