We are creating billing schedules and its line items(based on quote lines), based on term period and quantify specified we are calculating amount for each billing schedule.

enter image description here

our Requirement is SUM of Billing Amount should be = Net Amount on Quote. Problem that we are facing right now is after calculation, the amount is going off by few cents when term is Months + Few Days for months calculation where if its straight forward 12 its working fine.

Logic we are using to calculate billing amount is following

public static Double calculateBillingAmount(Date startDate, Date endDate, Decimal newNetUnitPrice, Decimal defaultSubTerm, Decimal Quantity){
    Double billingAmountforDays;
    Double billingAmountforMonths;
    Double totalBillingAmount;

    //get Months Between
    Integer monthsBetween = getMonthsBetweenFromStartDate(startDate, endDate);

    //get Days Between
    Integer daysBetween = getRemainderDaysBetweenFromStartDate(monthsBetween, startDate, endDate);

    //Calculate Billing Amount for Months
    billingAmountforMonths = newNetUnitPrice * getProratedMultiplierForMonth(decimal.valueof(monthsBetween)) * Quantity;

    //Calculate Billling Amount for Days
    billingAmountforDays = daysBetween != 0 ? newNetUnitPrice * getProratedMultiplierForDays(decimal.valueof(daysBetween)) * Quantity : 0.00;

    //Calculate Total Billing AMounts 
    totalBillingAmount =  billingAmountforMonths + billingAmountforDays;  

    return totalBillingAmount;

Where prorated multiplier for months is monthsBetween/12 and for days it will be ((daysBetween/(365/12))/12).

Here for the billing schedule where Term is 3 Months and 1Days e.g the billing amount is rounding off to 43,976.71 ideally the number should come up as 43,976.76, so that it gets matched with Quote Net Amount.

Can anyone advise how we can get correct number when decimal places needs to be considered.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.