Convert string in a specified culture-specific format to BigInteger in CSharp

Description

The following code shows how to convert string in a specified culture-specific format to BigInteger.

Example


  //  w  w w.  ja v a  2  s .  c  o  m
  
  
  


        
using System;
using System.Globalization;
using System.Text;
using System.Numerics;

public class Class1
{
    public static void Main()
    {
        BigInteger number = BigInteger.Parse("~6", new BigIntegerFormatProvider());
        Console.WriteLine(number.ToString(new BigIntegerFormatProvider()));
        Console.WriteLine(number);
    }

}

public class BigIntegerFormatProvider : IFormatProvider
{
    public object GetFormat(Type formatType)
    {
        if (formatType == typeof(NumberFormatInfo))
        {
            NumberFormatInfo numberFormat = new NumberFormatInfo();
            numberFormat.NegativeSign = "~";
            return numberFormat;
        }
        else
        {
            return null;
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var