In today’s post, we’ll look at a feature that requires us to perform a calculation with four decimal places instead of two, so that there is no money loss and it will increase the total annual revenue which will impact on financial growth for an organization. This feature can be used to calculate the prices of products with four decimal places.
For example, suppose a customer wants to buy 5 kWh of electricity, for which you charge a per-unit price. If the per-unit charge is 0.0089 cents, you can accurately calculate the power charges using the extra decimal places. Normally, we can only calculate to two decimal places, but in usage-based pricing, we can enable multiple decimal places.
When calculating product charges, two decimal places are typically used in the calculations. However, you can use additional decimal places in the Industries CPQ Cart to calculate one-time and recurring charges for your products in usage-based pricing. This feature can be used to calculate the prices of products with four decimal places.

How do we make this feature available?
You must modify the cpq-base-grid template in order to enable usage-based pricing with multiple decimal places. All of the child templates of the grid template are affected by the changes made to it. The correct decimal separator is also displayed when calculating the Monthly Recurring Charges (MRC) and Non-Recurring Charges using this template, which sets it based on the customer’s location and currency (NRC).
To Enable this feature, you have to follow these steps :
- Clone the cpq-base-grid Template.
- Clone the cpq-base-grid Layout.
- Enable the cpq-base-grid-currency-filter Layout.
STEP 1
Clone the cpq-base-grid template as the first step in enabling multiple decimal places in usage-based pricing.
Look for cpq-base-grid template. Expand it, clone it, rename it, and paste the code below into the template.
// Override default currency filter to support 4-digits
vlocity.cardframework.registerModule.filter("currency", ['$rootScope', 'ISO_CURRENCY_INFO', function($rootScope, ISO_CURRENCY_INFO) {
// Filter defaults
const defaultCurrencyCode = 'EUR';
const defaultFraction = 2;
return function (input, currencyInfo) {
if (input === undefined || input === null || input === '') {
return '';}
let fraction = defaultFraction;
if (String(input).includes('.')) {
const fractionStr = String(input).split('.').pop();
// when the fraction is more then 2 digits and those digits are not 0s then display these digits in the UI//
otherwise display as a normal currency (2 digits)
if (fractionStr.length > 2 && fractionStr.substr(2) !== '00') {
fraction = 4;
}
}
const isoCurrencyCode = (currencyInfo && currencyInfo.expression) || ($rootScope.vlocity && $rootScope.vlocity.userCurrency) || defaultCurrencyCode;
const currencySymbol = (currencyInfo && currencyInfo.isSymbol && currencyInfo.expression) || ISO_CURRENCY_INFO[isoCurrencyCode].text;
const currencyDecimal = ISO_CURRENCY_INFO[isoCurrencyCode].decimal ? ISO_CURRENCY_INFO[isoCurrencyCode].decimal : '.';
const currencyGroup = ISO_CURRENCY_INFO[isoCurrencyCode].group ? ISO_CURRENCY_INFO[isoCurrencyCode].group : ','
const [number, decimalFraction] = parseFloat(input).toFixed(fraction).split('.');
return currencySymbol + ' ' +
number.replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1' +
currencyGroup) +
currencyDecimal + decimalFraction;
};
}]);
STEP 2
Clone the cpq-base-grid-layout as the second step to enable multiple decimal places in usage-based pricing.
- Search for cpq-base-grid and click on the arrow to expand it.
- Click on a cpq-base-grid layout version.The cpq-base-grid layout page opens.
- Click Clone.The Clone Layout dialog box is displayed.
- Enter a name in the Layout Name field, for example, cpq-base-grid currency filter.
- Select Layout in the Layout Type field.
- Enter a name in the Layout Author field.
- Click Save.
- In the Template field, select the template that you cloned in the previous procedure.
- Save the layout.
STEP 3
Enabling the cpq-base-grid-currency layout in the Visualforce HybridCPQ page is the third step in enabling multiple decimal places in usage-based pricing.
Locate the HybridCPQ page, open the page, and replace cpq-base-grid with the layout name you cloned for the currency filter to update the layout name and save it.

Note : To enable additional decimal places in calculations, you must specify the layout name that you cloned in the Visualforce HybridCPQ page.
Hope this information helps you guys.
Cheers!!!
Mukul Sharma