Formula for number is decimal or not in Crystal Reports
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
You can also:
- add the field to your report normally
- right click it, select "Format Field"
- Click the
Number
tab and clickCustomize
- 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.
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!
- 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
精彩评论