Effacer les filtres
Effacer les filtres

How can i change the result in the annualpayment in the table to a number with 4 decimal, and not in exponentioal form

1 vue (au cours des 30 derniers jours)
%Annual Payment for Loans
p = 55000; %in dollars
r = 0.066; %interest rate
n = 1:5; %year
%Formula to be Use
A = (p * ((r*(1+r).^n)./((1+r).^n - 1)));
year = n;
annualpayment = A;
Annual_payment_with_an_interest_rate = table(n',A','VariableNames', {'year (n)','annualpayment(A)'})

Réponse acceptée

Walter Roberson
Walter Roberson le 24 Oct 2023
%Annual Payment for Loans
p = 55000; %in dollars
r = 0.066; %interest rate
n = 1:5; %year
%Formula to be Use
A = (p * ((r*(1+r).^n)./((1+r).^n - 1)));
year = n;
annualpayment = A;
Annual_payment_with_an_interest_rate = table(n',A','VariableNames', {'year (n)','annualpayment(A)'});
format shorte
Annual_payment_with_an_interest_rate
Annual_payment_with_an_interest_rate = 5×2 table
year (n) annualpayment(A) __________ ________________ 1.0000e+00 5.8630e+04 2.0000e+00 3.0251e+04 3.0000e+00 2.0805e+04 4.0000e+00 1.6091e+04 5.0000e+00 1.3271e+04
format short
Annual_payment_with_an_interest_rate
Annual_payment_with_an_interest_rate = 5×2 table
year (n) annualpayment(A) ________ ________________ 1 58630 2 30251 3 20805 4 16091 5 13271
format long g
Annual_payment_with_an_interest_rate
Annual_payment_with_an_interest_rate = 5×2 table
year (n) annualpayment(A) ________ ________________ 1 58630 2 30251.490803485 3 20804.8550129967 4 16091.1678968697 5 13270.6382762213
format bank
Annual_payment_with_an_interest_rate
Annual_payment_with_an_interest_rate = 5×2 table
year (n) annualpayment(A) ________ ________________ 1.00 58630.00 2.00 30251.49 3.00 20804.86 4.00 16091.17 5.00 13270.64
That is, the "format" command affects how a table is displayed at the command window.
However if you want to display 4 decimal digits at the command line then you will need to change the content of the table variable using round() and use format longg -- but if you do then since 58630 is an exact value with no cents then longg format will not display the cents. To go further than that you need to change the content of the tables in other more obscure ways.

Plus de réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by