1212998 - How to format a number to not display the decimals trailing zeros in Crystal Reports?

SAP Knowledge Base Article - Public

# 1212998- How to format a number to not display the decimals trailing zeros in Crystal Reports?

### Symptom

• How to remove trailing zeros?
• When viewing numeric values in Crystal Reports, it displays unwanted trailing zeroes for the decimals.
• How to format a number to eliminate the trailing zeroes in Crystal Reports?

For example: The number field displays: 123.4500, and the desired result will be to display: 123.45

### Environment

• SAP Crystal Reports 2008
• SAP Crystal Reports 2011
• SAP Crystal Reports 2013
• SAP Crystal Reports 2016

### Reproducing the Issue

1. In Crystal Reports, create a report off any data source.
2. Insert a database field that contains numeric values with decimals.
3. Format the database field to display the maximum number of decimals.
4. When viewing the report it displays the numeric values like:

100.123000
276.001100
1245.123401
20.560000

How to display the above number, without the trailing zeros for the decimals, like:

100.123
276.0011
1245.123401
20.56

### Resolution

• To remove the decimals trailing zeros, create a formula that converts the number to a string, and removed the trailing zeros. To do so:

1. Create a new formula, and add the following code to it:

Local NumberVar MyValue  :=  <INSERT YOUR DATABASE FIELD HERE>  ;

Local StringVar MyString := ToText(MyValue,10,"",".");
Local StringVar Output   := Split(MyString,".")[1];
If Count(Split(MyString,".")) = 2 Then
(
MyString := Split(MyString,".")[2];
MyString := StrReverse(ToText(ToNumber(StrReverse(MyString)),0,""));
Output := Output + ( If MyString <> '0' Then "." + MyString )
);

Output

2. In the formula, insert the numerical database field where it is written: <INSERT YOUR DATABASE FIELD HERE>

3. Insert the formula on the report, instead of the numeric database field.

Now, when viewing the report, it will display the numeric value without trailing zeros for the decimals.

### Keywords

TRAILING ZEROS, ZEROES FORMAT DECIMAL, Crystal Reports Formatting Number, , KBA , BI-RA-CR , Crystal Reports designer or BusinessViews Manager , How To

### Product

Crystal Reports 2008 V1 ; SAP Crystal Reports 2011 ; SAP Crystal Reports 2013 ; SAP Crystal Reports 2016