Infolink

 

Search This Blog

Mar 25, 2014

How to Display the Actual Number with Decimal

When you configure how numbers display, you select the number of decimal places to show. Crystal Reports then rounds the display value to that decimal position and that is what you see. 

But what if you want to display the actual number? If the original number has no decimal places, you want to see that. If the original has three decimal places, you want to see all three.

You can do this using conditional formatting.
  1. Right click on the number field and select Format Field from the pop up menu. You see the Format Editor dialog.

  2. On the Number tab, click the Customize button. You see the Custom Style dialog.


  3. On the Number tab, click the Conditional Format button next to the Rounding option. Enter the following formula:

    If CurrentFieldValue = Int(CurrentFieldValue)
    Then 0
    Else
    If
    CurrentFieldValue * 10 = Int(CurrentFieldValue * 10)
    Then 1
    Else
    If
    CurrentFieldValue * 100 = Int(CurrentFieldValue * 100)
    Then 2
    Else
    If
    CurrentFieldValue * 1000 = Int(CurrentFieldValue * 1000)
    Then 3
    Else
    If
    CurrentFieldValue * 10000 = Int(CurrentFieldValue * 10000)
    Then 4
    Else
    DefaultAttribute
  4. Click on the Conditional Format button next to the Decimal option and paste the same formula.
  5. Click on OK twice to return to your report and view your formatting changes:
      
This will show the correct values up to four decimal places. If you need to accommodate more decimal places, you can expand the formula by adding more IF statements.

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...