Round up double value in jasper report - jasper-reports

I have a textfield in jasper report as follows :
<textFieldExpression class="java.lang.Double"><![CDATA[$V{v_vcTotal}]]></textFieldExpression>
I want to round up this value using HALF_UP rounding mode.Can i achieve this in a simple way.Thanks in advance.
EDIT : I dont want to change my java class. Is there anything i can do in jasper jrxml file.

So all credit to #utkarsh their expression is so far the only working one I've seen online that converted my 'double' numbers pulled onto my report, my expression:
$f{balance}
Would produce doubles from a calculated field in my database like "-1365.00000000003"
In the Expression editor (in lieu of changing it in the source tab) I wanted to pull 2 sig figs from the number for looks. I added this expression and I stopped getting "compilation" errors and the wanted results:
new BigDecimal($F{balance}).setScale(2, BigDecimal.ROUND_HALF_DOWN).toString()
Result would be "-1365.00"
From what I've read this is a bit overkill to get the desired result but I am also under a deadline so I will try to optimize some other time.

Related

How to do conditional sum in Crystal Report

Question originally posted in Spanish, on es.stackoverflow.com, by Sebastián Miranda:
I am working with Crystal Report since Visual Studio 2017, I was asked
to make a sum to group, I have 3 options: Credit Notes, Ballot and
Invoice.
The first thing I did was to create a Formula Field with the name
NumberValorCif to convert the ICIF Value that I have to numeric with ToNumber (). I saved this and created another formula field
named SumCIFCredito that has the following code:
If {CobroPorcentaje.TipoDoc} = 'Credit Notes'
then {#NumberValorCif}
else 0
I saved, compiled and ran the application and it worked without any
problems ... but. I wanted to do the same for SumCIFBoleta:
If {CobroPorcentaje.TipoDoc} = 'Ballot'
then {#NumberValorCif}
else 0
But I don't add anything. I'm missing something? or I have to create
another variable.
I hope someone can help me.
Thank you so much
It sounds like you simply need to add the actual SUM of that new formula.
Place the new formula in the detail section, select it, hit the Sigma button to sum it, and elect to generate subtotals for your Grouping level.

Crystal Reports - suppress subreport parameter prompts

I have a Crystal report with several subreports linked on a common field - all working great. Now must add another, very complex, existing report as a new sub. This report's data source code stretches several pages. It also has over a dozen parameters which are further imbedded in numerous formula fields through out. That said, it runs fine and has a parameter that links with the main report. Unfortunately all the other parameter prompts is supremely annoying.
I've searched high and low for a method to accept default values without prompts but Crystal doesn't seem to accommodate that notion.
Revising the report to remove all the unneeded parameters would be extremely painful and simply not an option.
I'm hoping to find an alternate way to pass the parameter values to prevent the prompt. I'm aware of the SetParameterValue() method of the ReportDocument class but not sure how to use it. I've found examples of how to use it with C#, VS, ASP.net, etc., none of which work for an end user like myself.
Could the data source command itself be used?
Much thanks for any recommendations, guidance or thoughts!
With Command Level prompts, you would never be able to change the prompt values with the CR Viewer.
If the report is supposed to be viewed in the CR Viewer and you need the functionality or changing prompt values, try this:
1) Remove Command Level prompts
2) Create the Data prompt in the report from the Field Explorer
3) Create a Record Selection formula like this:
{date_field} = {?Date_prompt}
under Report > Selection Formulas > Saved data
4) Save the report with data
Try this...

Issue with passing field variable to subreport from master report

I am trying to do a simple expression in iReport, but whatever I try seems hasn't given me which I expected. It seems like such a simple thing to do, but I couldn't understand what's happening with my code.
All I'm trying to do is show a subreport when the value of an string field is a simple word like "VALUE". I am using the Print When Expression for the subreport control, however I'm not able to the see or reproduce this text with this expression. For me seems that I'm not passing well the parameters I wan't to use to do the print when expression in the subreport from the master report.
Is a disclaimer, so in master report I have a simple subreport, with the same conection from master and one parameter called Entity = "_id.Entity" (we use mongodb to get the fields for the report with a $group) and in the subreport part I have 2 text fields, the first one have the print when expression when P{Entity}.equals("VALUE"), the second one don't have any condition so this works perfectly, but the textfield with the condition doesn't work.
Any help would be appreciated. Thanks.

iReport sum of two measures

I'm having problem with JasperReports report by getting sum of two fields.
I have created so far variables that holds fields "TareWeight" variable that is casting values from double to float
new Float($F{EquipmentTareWeightKg})
"CargoWt" variable that is casting from string to float, etc...
Float.parseFloat($F{UfvFlexString03})+Float.parseFloat($F{UfvFlexString04})
So now I have two variables which I can manipulate with.
The problem starts when I wish to do a "recap" using crosstab. I have setup two groups that is done with wizard, and added another in crosstab. (please refer to the printscreen below)
And now, I have created under measures SumOf Tare that is using variable TareWt, and SumOfCargoWt that is using variable CargoWt.
I have tried to create another Measure SumOfGrossWt that would do a sum of variables TareWt + CargoWt but I have got some nonsense values.
I have tried to do another approach by creating variable GrossWt that would basically do exact the same thing as previous attempt
$V{Tare}+$V{CargoWt}
or use an variable: GrossWt
$V{Tare}+$V{CargoWt} or new Float($F{EquipmentTareWeightKg})+(Float.parseFloat($F{UfvFlexString03})+Float.parseFloat($F{UfvFlexString04}))
None of these actually worked: (Sum should be done by "Sum Of Tare"+ "Sum of CargoWt" = "Sum of GrossWt") plese refer to the second picture.
Here is a complete jrxml code/file:
jrxml file
save it as *.jrxml
Can please someone help me find a solution? how can I sum those two measure fields and get correct values?
Since CargoWt field had some null values in database, addition float value with null is equal to null, so the only value which was displayed on report are the one that had values for CargoWt, all others with null value were "ignored".

Formatting a line chart

I have a line chart in a report (rdlc), that I cannot get formatted correctly. There are 2 main things I am trying to accomplish.
1) The x-axis is a date, right now it is being displayed as the full date with time, and I want it to be displayed as mm/dd/yyyy. I have attempted to change this by using =FormateDateTime(Fields!EndDate.Value, DateFormat.ShortDate) This is exactly how I saw it in Microsoft's examples, even the one included in VS2008 (what I am using), but for some reason it says that .ShortDate is and unrecognized identifier. I am thinking this might be a bug. So any ideas on how to get it into the mm/dd/yyyy format?
2) I want the values that are being plotted not to be there actual value but the previous values before added to the value. This is to accomplish a continual upward slope, showing the totals. I would also like to filter out zero's since the first 20 entries are so are 0. When I try to use the filter option it for some reason makes the chart just a flat line.
Any suggestions to any of these problems or a link to a good tutorial would be great as I am new to using these reports. Thanks!
Update: I have accomplished these by applying changes to the actual data being supplied, I would still like to know an easier better way to do this.
You can format the date in the lable under the general tab like this.
=Format(Fields!POWDate.Value, "M/dd/yyyy")
As of now I have fixed the problem by formating the data in the SQL query to the way I would like it to be displayed in the report.