public static void Main()
double dval = ToDouble(v);
double max = GetMaxValue(v);
string val = string.Format("{0,12:f9}", dval * 10.0 / (max + 1));
public static double ToDouble(Object obj) {
switch(Type.GetTypeCode(obj.GetType())) {
case TypeCode.Byte: return (byte)obj;
case TypeCode.Char: return (char)obj;
case TypeCode.Int16: return (short)obj;
case TypeCode.Int32: return (int)obj;
case TypeCode.Int64: return (long)obj;
case TypeCode.SByte: return (sbyte)obj;
case TypeCode.Single: return (float)obj;
case TypeCode.UInt16: return (ushort)obj;
case TypeCode.UInt32: return (uint)obj;
case TypeCode.UInt64: return (ulong)obj;
throw new ArgumentException();
public static double GetMaxValue(Object obj) {
switch(Type.GetTypeCode(obj.GetType())) {
case TypeCode.Byte: return byte.MaxValue;
case TypeCode.Char: return char.MaxValue;
case TypeCode.Int16: return short.MaxValue;
case TypeCode.Int32: return int.MaxValue;
case TypeCode.Int64: return long.MaxValue;
case TypeCode.SByte: return sbyte.MaxValue;
case TypeCode.Single: return float.MaxValue;
case TypeCode.UInt16: return ushort.MaxValue;
case TypeCode.UInt32: return uint.MaxValue;
case TypeCode.UInt64: return ulong.MaxValue;
throw new ArgumentException();