Follow by Email

Wednesday, May 18, 2016

How to ignore zero decimal place values in Crystal Reports

I had this requirement where I wanted to show a decimal number with 2 decimal points in my report but when there is no decimal value I wanted to show the integer part only i.e.


I wanted to show


50


instead of
50.00 (default behavior)


I had to define a custom formula for this


here is the procedure


  1. right click on your field in crystal report
  2. Format field
  3. Click on Number tab
  4. Press customize button
  5. Define a formula for Decimals as below
Crystal Report Formula
if CurrentFieldValue - truncate(CurrentFieldValue) <> 0 then
2
else
0


This basically means that if the current value has no decimals show 0 or no decimal places , else show 2.


Thanks to an answer in below stackoverflow thread from where I got to know about "CurrentFieldValue "


http://stackoverflow.com/questions/17284732/how-to-ignore-zero-decimal-place-values-in-crystal-reports


No comments:

Post a Comment