Dividing a Float Field by an Integer - jasper-reports

I am sure this has a simple answer, however it alludes me at the moment! I am wanting to convert a float field in a JasperReports report by dividing by an integer (in fact converting hours to days):
$F{Average} / 24
This results in a blank result. I have tried to use:
$F(Average).divide(java.math.BigInteger(24))
and similar, but get compilation errors.
Apologies if this is a bit simple, but it would be good to get some assistance!

You are missing the new keyword:
$F(Average).divide(new java.math.BigDecimal(24, 2, RoundingMode.HALF_UP))

Related

Tableau Decimal to String

I have a field which is a Number(decimal) here's one such example value:
1005.44
now if I try to convert that to a string to simply get me what is seen; I'd expect STR = 1005.44
but instead I get:
1005.4400000000001
thats from STR(ROUND(([FIELD]),2))
I see some other posts with similar issues but no found resolution?
This artifact isn't unique to Tableau and stems from how underlying databases store floating point numbers and deal with functions like rounding.
You should try the following:
str(int([FIELD]*100)/100)
This will multiply the number by 100, convert to an int, divide by 100, and then convert to a string.

Days between one date till today. Not difference (Spotfire)

I'm trying to find how many days between a date and today.
I'm able to get the correct number of days but it show as negative.
Integer(DateDiff("day",Date(DateTimeNow()),Date([LAST_RECORD_DT])))
I would like the same result but positive number.
Your answer in your comment is good, but this is better in my opinion:
If LAST_RECORD_DT is in the past (which seems to be the case for you):
Integer(DateDiff("day",Date([LAST_RECORD_DT]),Date(DateTimeNow())))
If LAST_RECORD_DT is in the future:
Integer(DateDiff("day",Date(DateTimeNow()),Date([LAST_RECORD_DT])))
If you want it to always be positive, you can use Abs:
Abs(Integer(DateDiff("day",Date([LAST_RECORD_DT]),Date(DateTimeNow()))))

spss-modeler date difference getting negative results

First of all, I'm new to SPSS modeler, sorry if my question sound too obvious for experts, but what I'm trying is to calculate the date difference between two date values ( arrive_Date , Depart_Date ) in (Hours), I used this function time_hours_difference , this function works okay if the Arrive_Date and depart_date are the same day, but if the days are different, the date difference is in negative value, I searched and enabled this option: Rollover days/mins in stream properties, but the problem remains the same.
I hope you can help me with this beginner question.
Thanks
Hope its not too late. You are getting negative values because time_hours_difference extract only the time from the two specified timestamps and computes the difference out of it. It doesn't take the date values into account.
For example:
time_hours_difference('2012-08-02 14:10:50,2012-08-05 13:36:26)
Output:
-0.573
Remember, here time_in_hours('0130') under time format 'HHMM' evaluates to 1.5.
Here is my solution: in order to take days into account, first extract date_days_difference and multiply it with 24 to bring it in Hours and then sum it up with the time difference using time_hours_difference.
date_days_difference(arrive_Date,Depart_Date)*24 +
time_hours_difference(arrive_Date,(to_string(datetime_date(arrive_Date)) >< " 23:59:00")) +
time_hours_difference((to_string(datetime_date(Depart_Date)) >< " 00:00:00"),Depart_Date)

In Julia, if date is 96, how can I make it 1996 in DateTime?

I have an array with strings of dates. The format is "2/27/16 3:47" so "m-d-y H:M". However, DateTime parses this as 0016-27-02T03:47:00. I would like to have the output be: 2016-27-2T03:47:00.
My code is:
map(date-> DateTime(date, "mm/dd/yy HH:MM"), datsub[:date])
Side question: The output type becomes Any. Is this the correct type or should it be DateTime or something similar?
As #akrun mentioned, you should add the year yourself:
Dates.Year(2000) + DateTime(date, "m/d/y H:M")
This is more explicit about exactly what is happening. Otherwise Dates would have to guess what exactly something like 97 means: 1997 or 2097, or actually year [00]97?
It's possible that you might want to come up with a reasonable cutoff for what year to add. You can try the following:
expandyear(date::DateTime) = date + (Dates.year(date) < 25 ? Dates.Year(2000) : Dates.Year(1900))
with whatever cutoff you think makes sense.
The issue with return types with map is a known problem that has been fixed in the latest v0.5 nightlies. Julia v0.5 is likely to be released in the near future, perhaps within several months.

DATEDIF statement in SharePoint not working properly

I am trying to calculate the amount of days between two dates but my formula doesn't seem to be working properly. It's as is the function is ignoring the years in the dates. My function is as follows:
=IF([Today's date]>[Expiration Date],-DATEDIF([Expiration Date],[Today's date],"d"),(DATEDIF([Today's date],[Expiration Date],"d")))
I receive this error if I use the above function(Owners removed):
But then I replace -DATEDIF([Expiration Date],[Today's date],"d") with -DATEDIF([Today's date],[Expiration Date]"d") i get this result:
This is telling me that both cases are being treated as IF([Today's date]>[Expiration Date] even though 3/24/2015 is clearly larger than 11/03/2014. Can somebody please tell me what I'm doing wrong? Thanks.
=[ExpirationDate] - [TodaysDate]