2
votes

In my table I have values as:

5
6
12.06
15.933

I need to display in Crystal Reports as

5
6
12.1
15.9

Can anyone get me formula to do above?

I tried this formula:

tonumber({table.field})

But I get the result as below which I don't want.

5.0
6.0
12.06
15.93
3

3 Answers

6
votes

You can also:

  1. add the field to your report normally
  2. right click it, select "Format Field"
  3. Click the Number tab and click Customize
  4. In the Decimals formula, enter something like: if {@test} - truncate({@test}) <> 0 then 1 else 0

The formula tests if the field is an int. If so, show 1 decimal place, otherwise show 0. This method has the advantage of not changing the datatype to text which will make totalling and calculating easier.

1
votes

Create a formula with:

if remainder({database.field},truncate({database.field})) = 0 then
  totext({database.field},0)
else
  totext({database.field},1);

This will however convert the number to text so if you have to do any calculations then just use the original {database.field} in your calculations. This will also round to one decimal place. Not the most elegant!

1
votes
  • Choose "format field" on the field you want to edit
  • In "Decimals" field out a Formula
  • Type this formula

     if(Int({Field})<>{Field}) 
      then 1 
      else 0