Priyanka
Priyanka

Reputation: 37

Double.PositiveInfinity in c# returns ∞; is there a method to display "Infinity"?

In .Net 4, Double.PositiveInfinity returns ∞

Is there a method to display "Infinity"

using System;

public class Program
{
    public static void Main()
    {
        Console.WriteLine("PositiveInfinity {0}.", (Double.PositiveInfinity));
    }
}

expected is PositiveInfinity Infinity., but the actual output is PositiveInfinity ∞.

Upvotes: 2

Views: 1048

Answers (1)

Praneet Nadkar
Praneet Nadkar

Reputation: 813

This can be done by configuring the Current Thread culture. You can set your positive and negative infinity symbols there. Something like this:

var ci = (CultureInfo)Thread.CurrentThread.CurrentCulture.Clone();
ci.NumberFormat.NegativeInfinitySymbol = "-Infinity";
ci.NumberFormat.PositiveInfinitySymbol = "+Infinity";                
Thread.CurrentThread.CurrentCulture = ci;

Console.WriteLine("PositiveInfinity {0}.", (Double.PositiveInfinity));

Hope this helps!

Upvotes: 8

Related Questions