namespace UglyToad.PdfPig.Tokens
{
using System.Globalization;
///
///
/// PDF supports integer and real numbers. Integer objects represent mathematical integers within a certain interval centered at 0.
/// Real objects approximate mathematical real numbers, but with limited range and precision.
/// This token represents both types and they are used interchangeably in the specification.
///
public class NumericToken : IDataToken
{
///
/// Single instance of numeric token for 0.
///
public static readonly NumericToken Zero = new NumericToken(0);
///
/// Single instance of numeric token for 1.
///
public static readonly NumericToken One = new NumericToken(1);
///
/// Single instance of numeric token for 2.
///
public static readonly NumericToken Two = new NumericToken(2);
///
/// Single instance of numeric token for 3.
///
public static readonly NumericToken Three = new NumericToken(3);
///
/// Single instance of numeric token for 4.
///
public static readonly NumericToken Four = new NumericToken(4);
///
/// Single instance of numeric token for 5.
///
public static readonly NumericToken Five = new NumericToken(5);
///
/// Single instance of numeric token for 6.
///
public static readonly NumericToken Six = new NumericToken(6);
///
/// Single instance of numeric token for 7.
///
public static readonly NumericToken Seven = new NumericToken(7);
///
/// Single instance of numeric token for 8.
///
public static readonly NumericToken Eight = new NumericToken(8);
///
/// Single instance of numeric token for 9.
///
public static readonly NumericToken Nine = new NumericToken(9);
///
/// Single instance of numeric token for 10.
///
public static readonly NumericToken Ten = new NumericToken(10);
///
/// Single instance of numeric token for 100.
///
public static readonly NumericToken OneHundred = new NumericToken(100);
///
/// Single instance of numeric token for 1000.
///
public static readonly NumericToken OneThousand = new NumericToken(1000);
///
public decimal Data { get; }
///
/// Whether the number represented has a non-zero decimal part.
///
public bool HasDecimalPlaces => decimal.Floor(Data) != Data;
///
/// The value of this number as an .
///
public int Int => (int)Data;
///
/// The value of this number as a .
///
public long Long => (long)Data;
///
/// The value of this number as a .
///
public double Double => (double)Data;
///
/// Create a .
///
/// The number to represent.
public NumericToken(decimal value)
{
Data = value;
}
///
public bool Equals(IToken obj)
{
if (this == obj)
return true;
if (!(obj is NumericToken other))
{
return false;
}
return Data == other.Data;
}
///
public override int GetHashCode()
{
return Data.GetHashCode();
}
///
public override string ToString()
{
return Data.ToString(NumberFormatInfo.InvariantInfo);
}
}
}