|
-
February 8th, 2012, 06:24 PM
#1
Basic Question about Math.Round and {0:C}
I'm just running through a C# book and had a question, In my visual studio 2010 I put this code in:
double inflation = .04, initialCost = 1.00, finalCost = 0, cost = 0, years = 3;
cost = initialCost * inflation + initialCost;
cost = cost * inflation + cost;
finalCost = cost * inflation + cost;
finalCost = Math.Round(finalCost, 3);
Console.WriteLine("In {0} years the item will cost {1:C} with a starting cost of {2:C} and an inflation rate of {3} ", years,finalCost, initialCost, inflation);
My question: With the" finalCost = Math.Round(finalCost, 3);" my output for finalCost is 1.13 but if I comment it out I get 1.12 output for finalCost.
Can someone tell me why this is and if I'm missing something?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|