Why is infinity printed as 8 in the Windows 10 console?
Be assured that the floating point value is +Infinity
if the numerator of a floating point division by zero is positive, -Infinity
if the numerator of a floating point division by zero is negative, and NaN
if the numerator and denominator of a floating point division are both zero. That's in the IEEE754 floating point specification, which is what C# uses.
In your case, the console is converting the infinity symbol (which is sometimes represented typographically as a horizontal 8 — ∞) to a vertical 8.
C# double to float conversion issue
It isn't converted to 8
(eight). It's converted to infinity, whose representation (∞
) looks like a sideways eight. It's possible that whatever environment you're viewing your output in displays this like an 8
due to font or culture settings.
Specifically, it's PositiveInfinity, whose docs clarify:
This constant is returned when the result of an operation is greater than
MaxValue
.
Infinity in interest calculation?
You are multiplying total by the rate each step through the while loop, which seems reasonable enough, but you also multiply total by the value of the variable "money", which as far as I can tell is the starting balance.
So you multiply by the starting balance 360 times. If only my savings accounts worked like that! I'm not sure if the rest of the logic is correct, but for a start, try moving the
total = total * money;
to be under the line
float total = 1;
(or better yet just change from
float total = 1;
to
float total = money;
and get rid of the line
total = total * money;
altogether)
Related Topics
The Application Called an Interface That Was Marshalled for a Different Thread - Windows Store App
Accelerating Bitmap Grayscale Conversion, Is Openmp an Option in C#
Yield Return Statement Inside a Using() { } Block Disposes Before Executing
Transparent Background on Winforms
Connecting to SQL Server with Visual Studio Express Editions
How to Clear Cookies Using ASP.NET MVC 3 and C#
Best Way to Handle Integer Overflow in C#
Convert Transparent Png to Jpg with Non-Black Background Color
Why Is There Not a 'Fieldof' or 'Methodof' Operator in C#
How to Run Something in the Sta Thread
Random Errors Using Wait for Element Clickable Method in Selenium
Multi Processes Read&Write One File
Xml Parsing - Read a Simple Xml File and Retrieve Values
How to Async Download Multiple Files Using Webclient, But One at a Time