Question


Cathay
CN
Last activity: 8 May 2025 1:57 EDT
Truncating Decimal places
We have a requirement where we have to limit the no of decimal places to 2. When the user enters the value in any amount fields, the entered value should be formatted in the proper decimal format as below.
1. If entered 12345 change it to 12345.00
2. If entered 12345.234 change it to 12345.23
3. If entered 12345.235 change it to 12345.23
We are using the Decimal control in which we have mentioned the Precision as 2 and we are refreshing the screen on change. When the user enters the value and Tab out, the first two scenarios works fine. But the third scenario is doing a round off and changes the value to 12345.24.
Also, if this field gets the cursor back, you'll see the original 12345.235. We just want to see the truncated numbers.
As this is an amount field the rounding off is not required. Please let us know how we can achieve this.
***Edited by Moderator Rupashree to add Capability tags***
-
Reply
-
Aditya Boggarapu -
Share this page Facebook Twitter LinkedIn Email Copying... Copied!


Pegasystems Inc.
GB
@LiXiangTang You can achieve this by customizing the OOTB Decimal control. In that control, the formatting is done by calling the method PRNumberFormat.format. If there are more decimal places than the value specified in the Precision param, it will be rounded off to the mentioned number of digits. To avoid rounding off, you can add a line to call the method "BigDecimal newValue = value.setScale(iPrecision, BigDecimal.ROUND_DOWN);" just above the PRNumberFormat method and pass the 'newValue' variable in the place of 'value'. This way, the decimal value will be truncated without rounding off, before calling the PRNumberFormat method.
⚠ This is a GenAI-powered tool. All generated answers require validation against the provided references.


Iffco Tokio General Insurance
IN
You may try below control
PABDecimal control under other categories and provide precision parameter to what you want to restrict.
It will not allow user to enter more than allowed decimal places.


Cognizant
IN
@Dev.Pega007 can you please share the snapshot how did you achieve it .I am also facing same issue like @LiXiangTang


Iffco Tokio General Insurance
IN
As we are using Pega Insurance framework so this control is available:
You may try below HTML snippet if same can help:
As we are using Pega Insurance framework so this control is available:
You may try below HTML snippet if same can help:
<SCRIPT> function FormatDecimal(oText) { <% int iPrecision = 2; String precisionParam = tools.getParamValue("Precision"); if (! precisionParam.equals("")) { try { iPrecision = Integer.parseInt(precisionParam); } catch (NumberFormatException nfe) { iPrecision = 2; } } else { iPrecision = 2; } %> var sText=oText.value; var iIndex=sText.indexOf('.'); var AfterPrec=""; var Precision = <%=iPrecision%>; if(iIndex >0) { AfterPrec= sText.substring(iIndex+1); if(AfterPrec.length >= Precision) oText.value=sText.substring(0,iIndex+Precision+1); } } </SCRIPT> <pega:choose> <pega:when test='$mode-input'> <input type="text" name="<p:r n='$this-name' m="NORMAL" />" value="<p:r n='$this-value' m="NORMAL"/>" size="10%" <pega:include name="ClientValidation" /> onKeyUp="FormatDecimal(this);" /> </pega:when> <pega:otherwise> <p:r n='$this-value'/> </pega:otherwise> </pega:choose>
Updated: 7 May 2025 9:26 EDT


Cognizant
IN
@Dev.Pega007 Directly I can create new control and simply put this code and I need to make precision to 6 basically so i will change it .is the understanding correct ?
Issue : The existing prod UDB is truncating the value, if the value passed to DB exceeds the defined scale (number of digits after decimal points).
Eg: For a column of type decimal (21,6), if the value is passed 1999.1234567 then UDB is storing the value by truncation as 1999.123456
Where-as PG is performing round-off, it is storing to the DB as 1999.123457
I want to stop rounding off basically
Can you please show me the configuration of the control and also where you are using this control and what parameters you are putting in control ? Great thanks in advance


Iffco Tokio General Insurance
IN
Seeing your problem statement: You want to prevent any value from rounding off the any floor or ceiling value
But
This control is to restrict user to put decimal value more than specified in snippet.
Same is not rounding off as well. You may try once by creating control and using the same in section to capture the value you intended to precise.
Thanks


Cognizant
IN
@Dev.Pega007 Thanks for your clarification . Can you please share the snapshot of the parameter tab of the control that you have made just to confirm whether you have defined any parameters or not .
Second things is ,can you please share the snapshot of the field where you are using it ,just to check all the configuration in general tab and in presentation tab .
Great thanks in advance
Updated: 8 May 2025 0:38 EDT


Iffco Tokio General Insurance
IN


Cognizant
IN
@Dev.Pega007Great thanks , we will be in touch :)