Monday, May 18, 2009

Removing decimal places in VS.NET 2008's Crystal Reports

There are times where the business requires numbers with decimal places to have those decimal places removed if the decimal value is zero. For example, it's better to display 707 than 707.00, but if it's 707.55, it still stays at 707.55. Here's how you can tell Crystal Reports to NOT use decimal places in this case.

  1. Open up the Crystal Report.
  2. Right-click on the decimal value field, then click on Format Object.
  3. Select the Number tab.
  4. Choose Custom Style, then click on the Customize button.
  5. Click on the X*2 button next to the Decimals drop-down box.
  6. Change it from Crystal Syntax to Basic Syntax.
  7. Enter something akin to the following code:If ({TABLE.DECIMALFIELD} - Round({TABLE.DECIMALFIELD}, 0)) = 0.0 Then formula = 0 Else formula = 1 End IfWhere 0 and 1 are the number of decimal places.
  8. Click on the Save and Close button.
  9. Click on OK twice, then save the report.

3 comments:

Anonymous said...

Thanks man, great tip !

psycho187 said...

What if there's no Number tab?

psycho187 said...

What if there's no Number tab? i mean, i have a formula that i created, it won't let me save as a number, so i'm displaying it as text, but i also would like to take the decimal places away from the value. how would i go about doing that?