62 lines
1.5 KiB
C#
62 lines
1.5 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using ln.type;
|
|
|
|
namespace ln.json
|
|
{
|
|
public class JSONNumber : JSONValue
|
|
{
|
|
public Decimal Decimal => decValue;
|
|
readonly decimal decValue;
|
|
|
|
public double AsDouble => (double)decValue;
|
|
public long AsLong => (long)decValue;
|
|
public int AsInt => (int)decValue;
|
|
|
|
public override object ToNative()
|
|
{
|
|
if (Decimal.Ceiling(decValue).Equals(Decimal.Floor(decValue)))
|
|
return (long)decValue;
|
|
return (double)decValue;
|
|
}
|
|
|
|
public JSONNumber(short i)
|
|
: this((long)i) { }
|
|
public JSONNumber(ushort i)
|
|
: this((long)i) { }
|
|
public JSONNumber(int i)
|
|
: this((long)i) { }
|
|
|
|
public JSONNumber(long integer)
|
|
: base(JSONValueType.NUMBER)
|
|
{
|
|
decValue = new decimal(integer);
|
|
}
|
|
|
|
public JSONNumber(uint i)
|
|
: this((ulong)i) { }
|
|
|
|
public JSONNumber(ulong integer)
|
|
: base(JSONValueType.NUMBER)
|
|
{
|
|
decValue = new decimal(integer);
|
|
}
|
|
|
|
public JSONNumber(double doubleValue)
|
|
: base(JSONValueType.NUMBER)
|
|
{
|
|
decValue = doubleValue.ToDecimal();
|
|
}
|
|
public JSONNumber(decimal decValue)
|
|
: base(JSONValueType.NUMBER)
|
|
{
|
|
this.decValue = decValue;
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return decValue.ToString(CultureInfo.InvariantCulture);
|
|
}
|
|
}
|
|
}
|