cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to Limit BigDecimal Value in Backoffice

Former Member
0 Likes
836

Hi,

I have used new attributes which have BigDecimal type. i tried to limit value to 2 decimal places but in backoffice its value is coming with multiple zeroes. How to Limit that value in backoffice.

                     <persistence type="property">
                         <columntype>
                             <value>java.math.BigDecimal</value>
                         </columntype>
                     </persistence>
                     <modifiers read="true" write="true" search="true" />
                     <defaultvalue>Double.valueOf(0.0d)</defaultvalue>
                 </attribute>

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Likes

Hi ,

my persistence attribute helped me in limitation:

                      <columntype>
                          <value>java.math.BigDecimal</value>
                      </columntype>
                  </persistence>
                  <modifiers read="true" write="true" search="true" />
                  <defaultvalue>Double.valueOf(0.0d)</defaultvalue>
              </attribute>
Former Member
0 Likes

Hi Sachin,

You can create a custom interceptor that runs before saving the model. The Interceptor creation and example usages can be found here: https://help.hybris.com/6.6.0/hcd/8bfbf43e8669101480d0f060d79b1baa.html

In that interceptor you will have to write something like this to limit the decimal spaces

 BigDecimal value = new BigDecimal(2.123456d);
 System.out.println(value); //Prints 2.1345600000...
         
 value = value.setScale(2, RoundingMode.CEILING);
 System.out.println(value); // Prints 2.13

Another possibility to achive that will be to use Dynamic Attributes as described here: https://help.hybris.com/6.6.0/hcd/8bb46096866910149208fae7c4ec7596.html

Best regards,