Adjust the number of decimals for a Quantity or Price field

Crystal Reports does not include an option to automatically adjust the number of decimals for a Number field. However, this can be accomplished with a simple formula for each field on the report.

  1. Right-click on the Field and choose Format Field…
  2. Select the Number tab
  3. Click Customize button
  4. Select Number tab
  5. Use the drop-down next to Decimals to select the maximum number of decimals (recommended = 1.0000000)
  6. Click X+2 button to the right of Decimals and paste formula code listed below
  7. Adjust the minDecimals to be the minimum number of decimals to be displayed (currently 2)
  8. Use the drop-down next to Rounding to select the maximum number of decimals to be rounded (recommended = 0.0000001)
  9. Click X+2 button to the right of Rounding and paste formula code listed below
  10. Adjust the minDecimals to be the minimum number of decimals to be displayed (currently 2)

Formula Code:

WhilePrintingRecords;
numberVar counter := 0;
numberVar minDecimals := 2;
numberVar num := CurrentFieldValue;

while truncate(num) <> num do
(num := num * 10;
counter := counter + 1);

if counter < minDecimals then
minDecimals
else
counter;

Posted in Reports - Last modified on September 15, 2017Brad Bearden
Still need help?
Search all content on this site, contact support at 817-870-1311, or create a support request.