The Arithmetic/addingNumbersWithCurrency extension adds two currency values from inside a Virtuoso journey.
This is useful when your test needs to calculate the total of two currency amounts while keeping the original currency symbol and its position.
Parameters:
-
Number1required, the first amount as a text value with a currency symbol, for example$10.50,10.50$, orRs20.50; -
Number2required, the second amount as a text value with the same currency symbol asNumber1, for example$5.75,5.75$, orRs5.75.
Note: Both values must use the same currency symbol. If the symbols are different, the extension throws a Different currency symbols error.
NLP usage
Use the extension in a journey by calling Arithmetic/addingNumbersWithCurrency with the execute command. Pass each value to the matching extension input using as inputName.
Note: The result keeps the currency symbol in the same position as the first value. For example, $10.50 returns a result with the symbol at the start, while 10.50$ returns a result with the symbol at the end.
To add two currency values with the symbol at the start:
execute "Arithmetic/addingNumbersWithCurrency" using "$10.50" as Number1, "$5.75" as Number2 returning $TotalTo add two currency values with the symbol at the end:
execute "Arithmetic/addingNumbersWithCurrency" using "10.50$" as Number1, "5.75$" as Number2 returning $TotalTo add two values using a text currency such as Rs:
execute "Arithmetic/addingNumbersWithCurrency" using "Rs20.50" as Number1, "Rs5.75" as Number2 returning $TotalYou can also use Virtuoso variables to make the same step reusable across different amounts:
execute "Arithmetic/addingNumbersWithCurrency" using "$amount1" as Number1, "$amount2" as Number2 returning $TotalExample setup using variables before calling the extension:
store value "$10.50" in $amount1
store value "$5.75" in $amount2
execute "Arithmetic/addingNumbersWithCurrency" using "$amount1" as Number1, "$amount2" as Number2 returning $TotalFor example, adding $10.50 and $5.75 returns:
$16.25This extension does not require any external resource.
The extension should be configured as:
- Run asynchronously: No
- Scope: Global
Limitation: This extension performs simple currency text parsing. It does not perform currency conversion and does not validate locale- specific number formatting beyond extracting numeric values and the currency symbol from the provided strings.
Add the extension to your Virtuoso instance
Select the domain that matches your Virtuoso account.
View source
Last updated: 22/05/2026
Resources: None
// Note this extension is not a product feature of Virtuoso and is not officially supported
// Extensions use javascript which may or may not be compatible with systems under test (SUTs)
// We welcome you to use this extension or adapt it for your needs
// adds two numbers with the currency symbol
function addCurrencyNumbers(number1, number2) {
// Helper function to extract the numeric value from the string
function extractValue(str) {
return parseFloat(str.replace(/[^0-9.-]/g, ''));
}
// Helper function to extract the currency symbol from the string
function extractSymbolAndPosition(str) {
const match = str.match(/([^\d.-]+)?([\d.,-]+)([^\d.-]+)?/);
if (match) {
return {
symbol: match[1] || match[3] || '',
position: match[1] ? 'start' : 'end'
};
}
throw new Error('Invalid format');
}
// Extract values and symbols
const num1 = extractValue(number1);
const num2 = extractValue(number2);
const { symbol: symbol1, position: position1 } = extractSymbolAndPosition(number1);
const { symbol: symbol2, position: position2 } = extractSymbolAndPosition(number2);
// Check if both numbers have the same currency symbol
if (symbol1 !== symbol2) {
throw new Error('Different currency symbols');
}
// Add the numbers
const sum = num1 + num2;
// Format the result with the currency symbol in the correct position
const result = position1 === 'start' ? `${symbol1}${sum.toFixed(2)}` : `${sum.toFixed(2)}${symbol1}`;
return result;
}
// Example usage:
const number1 = Number1;
const number2 = Number2;
const sum = addCurrencyNumbers(number1, number2);
console.log(sum); // Output
return (sum);
Comments
0 comments
Please sign in to leave a comment.