1
good afternoon.
An Internet exercise asks to calculate how long a given investment can pay a debt, both growing at an interest rate per month.
Observe the created process
declare @divida real = 10000
declare @aplicacao real = 1500
declare @taxa_div real = 0.025
declare @taxa_apli real = 0.04
declare @meses int = 1
while (@divida > @aplicacao) begin
set @divida = (@divida * @taxa_div) + @divida
set @aplicacao = (@aplicacao * @taxa_apli) + @aplicacao
set @meses = @meses + 1
end
print @meses
select @divida
select @aplicacao
print @divida
print @aplicacao
print @aplicacao - @divida
At the end I am displaying the values when I observed the following points :
- At the end when I ask to display the values with PRINT is not displayed with decimals already, using SELECT the decimals are displayed.
- When I ask to subtract the values, the result is displayed with decimals.
Does anyone have an idea of why?
Only one detail, if you ask to display the values of debt and application within the WHILE some will be displayed with decimals and others will not. Some idea?
– Enio Lacerda
I took the test here and everyone’s gone with decimal places.
– rubStackOverflow
leaves variables as real or float
– Enio Lacerda
It will depend on the use, for monetary values I think the best is the
decimal
.– rubStackOverflow
I agree with you. I just wanted to understand the reason for this behavior.
– Enio Lacerda