Why Is Infinity Printed as "8" in the Windows 10 Console

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



Leave a reply



Submit