Solved

How to format a numeric field in Crystal to print an integer or a decimal depending on the value.

Posted on 2013-06-19
8
492 Views
Last Modified: 2013-06-20
What would be the appropriate way to format a numeric field so that it will not print any zeros to the right of the decimal point.

8.00 would print as 8
1.40 would print as 1.4
1.36 would print as 1.36
0
Comment
Question by:Joe Brown
  • 4
  • 2
  • 2
8 Comments
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
Do you only need 0, 1, or 2 decimals?

mlmcc
0
 

Author Comment

by:Joe Brown
Comment Utility
I need all 3 if the number goes out that far. So, If I set the field to have 2 decimals, and the value returned on the report is 8.00 - how can I get that to report as 8. How can I get 1.40 to print as 1.4?

I want it to drop any zeros to the right of the decimal point and remove the decimal and print as an integer if it is a whole number.
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
You don't ned to go to 3 decimals ever? Say 1.125?

mlmcc
0
 
LVL 34

Expert Comment

by:James0628
Comment Utility
Assuming that you never want to see more than 2 decimal places, you could create a formula similar to the following and put it on the report:

if Int ({field}) = {field} then
  CStr ({field}, 0)
else
  if ({field} * 100) \ 10 = {field} * 10 then
    CStr ({field}, 1)
  else
    CStr ({field}, 2)


 That seems to work.  It converts the number to a string, using different numbers of decimal places, based on the value.  FYI, the backwards slash (\) is integer division in CR.

 One basic limitation with that approach is that you won't be able to do summaries on that report field, because it's a string, but if you need a summary, you can just put the actual field on the report too, but suppressed, and then summarize that.


 FWIW, there are several other ways that you could handle those decimals.  That's just one option.

 James
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 100

Accepted Solution

by:
mlmcc earned 250 total points
Comment Utility
You can also control it through the format

Right click the field
Click FORMAT FIELD
Click the NUMBER TAB
Click CUSTOMIZE
CLick the formula button to the right of DECIMALS

if Int ({field}) = {field} then
     0
else  if (Int({field} * 10) = {field} * 10 then
    1
  else
    2

mlmcc
0
 
LVL 34

Assisted Solution

by:James0628
James0628 earned 250 total points
Comment Utility
I think you've got an extra "(",  or left out a ")".

else  if Int({field} * 10) = {field} * 10 then


 James
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
You're right

if Int ({field}) = {field} then
     0
else  if  Int({field} * 10) = {field} * 10 then
    1
  else
    2
0
 

Author Comment

by:Joe Brown
Comment Utility
Wonderful. This works. Thank you for the formula mlmcc and the correct James.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now