0

I use a sample calculator in the excel to create a new one using JavaScript. when i calculating the Cost(dirty) the answers i got is different from the answer. in the excel. So i tried in these in excel

  • First i use the cell for the calculations it give the same answer as in the excel (EG:=C13/100*C20). i got 960,918.00
  • Then i tried the values it gives different answer but same as i get from the JavaScript (EG: =96.09*(1000000/100)). i got 960900.

Excel calculations
Last coupon date: =COUPPCD(C2,C4,2,1)
Next coupon date: =COUPNCD(C2,C4,2,1)
Clean price: =ROUND((PRICE(C2,C4,C5,C7,100,2,1)),4)
Accrued interest: =ROUND(ACCRINT(C9,C11,C2,C5,100,2,1),4)
Dirty Price: =C15+C18
Cost(dirty): =C13/100*C20

I am unable to include a screenshot so i mention like this

C2: 24-Aug-2008, C4: 01-Apr-2018, C5: 16.00%, C7: 18.29%, C9:Last coupon date. C11: Next coupon date, C13: 1000000, C15: Clean price, C18: Accrued interest, C20: Dirty Price, C23: Cost(dirty).

Please help me, i don't know why the two answers are different

FYI: I tried whether the value in the C20 and 96.09 are same, i get FALSE as result and they don't have any different also.

I really confused with this and i get stuck please give some solutions if you can.
Thanks in advance

1 Answer 1

0

The problem is - you are having 96.0918 in your cell C20 which is derived using =C15+C18 (DirtyPrice) And you are comparing it with 96.09 (using JS).

If you want to have the same result as your JS/calculator then you need to round it like =ROUND(C15+C18,2)

If you are seeing 96.09 in your cell C20 then just format it to have General formatting or to have 4 decimal places. You can do that by right click on cell and select Format Cells option.

Hope this will help you.

1
  • Thanks its worked. Round function help to change in the excel, but is there any way to do same as in the excel answer in javascript
    – Kuru
    Apr 16, 2015 at 8:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.