Crystal Reports - Disable default rounding/Show all decimals - crystal-reports

If I create a Formula Field A containing only 1/1000 and then drag it out into the report it will show "0,00" due to default number of decimals is set to 1.00 and default rounding is set to 0.01 for a field of with the type Number.
No problems.
When decimals and rounding are adjusted it will show 0,001.
When I create Formula Field B that only contains {#A} and increase decimals and rounding it will show as "0,001000000000".
But if I use A to create a text, totext({#A}) + ' test', the result will be "0,00 test" and I can not figure out a way to show the correct "0,001 test" without adding totext({#A},3). I don't want to use rounding because the number of decimals in A varies and I don't want to show any zeroes at the end.
I did modify this code (could be used in conditional formatting of decimals for a number field):
If CurrentFieldValue = Int(CurrentFieldValue) Then 0
Else If CurrentFieldValue * 10 = Int(CurrentFieldValue * 10) Then 1
Else If CurrentFieldValue * 100 = Int(CurrentFieldValue * 100) Then 2
Else If CurrentFieldValue * 1000 = Int(CurrentFieldValue * 1000) Then 3
Else If CurrentFieldValue * 10000 = Int(CurrentFieldValue * 10000) Then 4
Else DefaultAttribute
to
If {#A}= Int{#A} Then totext({#A},0)
Else If {#A}* 10 = Int{#A}* 10) Then totext({#A},1)
...
It works but I was hoping I wouldn't need all that extra code, I already have performance issues in my Crystal Reports and I don't want the risk of adding to that.
I just want to use the actual value in {#A} no matter the number of decimals.
I guess this could be caused by both default rounding settings as default number of decimals
And now I realise this might be caused by default number of decimals, not rounding.
If I change A to (1/1000)*6 it will show up as 0,01 unformatted, B will show "0,00600000 test". So it is a rounding problem.

Leave the output of your desired formula as a number.
Right click on the formula and select format field.
In the number tab select Custom Style and click customize.
For rounding option select 0.0000000001
Click the X-2 next to the Decimals option and enter this formula
local numbervar a;
local numbervar b;
for a := 1 to 10 do
(
if mid(strreverse(totext(CurrentFieldValue,10)),a,1) <> "0" then
(b := a;
a := 10);
);
11- b

I have found that the default rounding is defined by your system regional settings. If you increase the number of decimal places from 2 (usual) to say 8, all your problems will be resolved.

Related

Summary Percentage Yes vs No

Basically I'm looking for a formula to see how many times Yes was used vs. No.
I have something like this:
(({Command.result} ="Yes") / {Command.result})*100
Which makes sense in my head, but I keep getting:
A number, or currency amount is required.
Your current formula attempts to divide a boolean type through by a string. You can only perform division with numbers.
Instead, create two formulas as individual counts of Yes or No:
#YesCount:
If ({Command.result} = "Yes") Then 1 Else 0
#NoCount:
If ({Command.result} = "No") Then 1 Else 0
For the percentage, create two more formulas:
#YesPercent:
100 / Count ({Command.result}) * Sum ({#YesCount})
#NoPercent:
100 / Count ({Command.result}) * Sum ({#NoCount})

How to display quotient as a percentage

I am using Postgresql to generate a simple quotient of two fields " a / b " = -3 / 300 = -.01 or -1.00%. Instead it displays as zero. I've tried many variations of to_char with no success. How could I get "select -3/300 as quotient" to display the quotient in xxx.xxx% format? Thanks
To display with the percentage sign, you can use the following format. Don't forget to first multiply by 100.0 so 1) is it indeed a percentage and 2) as noted by #dhke the computation is done with floats, not integers.
select to_char(100.0*-3/300,'999D99%') a;
a
----------
-1.00%
(1 row)

Calculation of Previous field

New to CR and use CR v10 and SQL Server 2000.
For the first record i.e Beginning Balance , the calculation is sum(field) from the input date, which I have calculated in SP as BegDateSum
But for the rest of the records under a group, the calculation should be previous(balance)+IN+OUT
Sample has been given:
Date Doc Descrip IN OUT Balance
Group Header-------- Beginning Balance-------------- 50 <---- sum(field) from my inputdate
3/2/2012 A -1 0 49 <-- (50+(-1)+0)
4/2/2012 B -2 0 47 <-- (49+(-2)+0)
5/2/2012 C 0 3 50
6/2/2012 D -2 3 51
How do I achieve this?
I am not sure whether to use running total, in case I have to how to do it.
A running total field won't work in this case, they are designed to add up (or count, or average, etc) one field and give you the sub-totals automatically. But, we can do some custom functions that will give the results you need. Assuming that your initial 50 is a static value, you would set a variable to that amount, and then add the IN and OUT values as you go along (printing that result of that).
First, initialize the value in the report header with a formula like:
WhilePrintingRecords;
Global NumberVar Balance;
Balance := 50;
""; //print nothing on the screen
Then, the formula to calculate and show the new balance, in the bar where the data is:
WhilePrintingRecords;
Global NumberVar Balance;
Balance := Balance + {tableName.IN} + {tableName.OUT};
The last line both calculates the new value, and tells what the result of the formula should be.
If the "50" is calculated somehow, then that will have to be done before the formula that calculates the new balance. If it is based off of the first record read in, you'll want to use a formula that includes If PreviousIsNull({tableName.Balance}) Then ..., that is usually a good indicator of the first record in the data set (unless that field can be null).

Sumifs in Crystal

I'm working on a database that basically looks like this (in its simplest form):
{Phase} {Code} {Qty}
Example:
{Qty} for {Phase}="R" and {Code}="Nat" = 0
{Qty} for {Phase}="F" and {Code}="Nat" = 5
{Qty} for {Phase}="R" and {Code}="Int" = 10
{Qty} for {Phase}="F" and {Code}="Int" = 15
I am trying to get a result to show me the Qty for phase "R" and Code "Nat" (where R is <> 0) otherwise give me the qty for phase "F". So for the above example I would get an answer = 5 for Nat (because qty for phase R is 0) and an answer of 10 where the code is Int (because qty for phase R <> 0)
I have used three formula fields to do this:
1: if ({PHASE}="F" and {CODE}="NAT") then {QTY} else 0
2: if ({PHASE}="R" and {Code}="NAT") then {QTY} else 0
3: if {2} = 0 then {1} else {2}
Formula fields 1 & 2 come up with the correct amounts. However formula field {3} returns both phases. For example Code "Int" Phase "R" shows as qty = 25 instead of qty = 10.
How do I get around this?
You need to group by {table.code} because this is not a one-row calculation, but needs to be a calculation over each code for 2+ phases (meaning 2+ rows of data).
Create a formula with two variables that will store the values of each phase, F and R. This formula needs to go in the Details section of the report.
whileprintingrecords;
numbervar Fqty;
numbervar Rqty;
if {table.phase}="F" then Fqty:={table.qty}
else Rqty:={table.qty};
Now, in the group footer, you can reference both quantity values via the variables.
whileprintingrecords;
numbervar Fqty;
numbervar Rqty;
if Fqty=0 then Rqty else Fqty
And you're done. Don't forget to reset the two variables in the group header so you don't carry the quantity over between different codes.

Crystal summary and percents

I have a Crystal Report v 9.2.2 and I have three summaries at the end of each group; count of IEP students, count of non-IEP students, and total number of students. For an example, for one group (a class) I have 25 students. 4 Students are IEP, 21 are non-IEP. So I tried to create a formula to calculate the percentages, but the percents are wrong.
sum({#IEP}) % count({Mytable.student_id})
Manually, the math says 4 / 25 * 100 = 16, but when I use the formula above I get 11
I don't think it's a formatting problem.
Check reset value in "Create running Total Field" for the count.
Or
reset the count in the formula.
Your math is right, just do the same thing in the code/formula. The following works for a group based on {YourGroupField} and gives the percentage to one decimal point:
local numbervar IEPstudents := sum({#IEP},{YourGroupField}) //get number of IEP students in group
local numbervar TotalStudents := count({Mytable.student_id},{YourGroupField}) //get total students in group
local numbervar ThePercent := (IEPstudents / TotalStudents) * 100;
totext(ThePercent,1) + '%'
Alternatively, you can keep the formula numeric and add the percent symbol and formatting in the field's format editor.