Reputation: 70
I have a Spring Boot method in which I have a variable to calculate the vacation days (VACATION_DAYS_GEN_DAILY), the problem is that when I show them in the front it jumps with all the decimals. I need to know how I can remove those tell them.
private static final double VACATION_DAYS_GEN_DAILY = 22.0 * 4 / (365 * 4 + 1);
public EmployeeDashboardDto getEmployeeDashboardYearDto(Integer year, Integer employeeId) throws QOException {
LocalDate fromDate = LocalDate.of(year, 1, 1);
LocalDate toDate = LocalDate.of(year, 12, 31);
double leftVacationDays;
double vacationsPerWorkedDays = 0;
int pastVacations = 0;
EmployeeView emp = employeeService.getById(employeeId).getBean();
if (fromDate.isBefore(toDate)) {
vacationsPerWorkedDays = (ChronoUnit.DAYS.between(fromDate, toDate) - AbsenceDays + 1)
* VACATION_DAYS_GEN_DAILY;
}
leftVacationDays = emp.getCummulatedVacationDays() + vacationsPerWorkedDays;
employeeDashboardDto.setLeftVacationDays(leftVacationDays);
return employeeDashboardDto;
}
Upvotes: 0
Views: 73
Reputation: 1987
This link maybe helpful or you can use this:
double roundOff = Math.round(VACATION_DAYS_GEN_DAILY * 100.0) / 100.0;
the output:
21.98
Upvotes: 1