Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Number values formatted in scientific notation #1

Open
cpmohanraj opened this issue Dec 21, 2020 · 1 comment
Open

Number values formatted in scientific notation #1

cpmohanraj opened this issue Dec 21, 2020 · 1 comment

Comments

@cpmohanraj
Copy link

The number values are formatted in scientific notation and lose precision.

@cpmohanraj
Copy link
Author

cpmohanraj commented Dec 29, 2020

I haven't used C# prior but I have found my way through stack overflow to check for numeric types and converted them to double.

Changed the PIDataRetrievalAsync.cs

Object val;
val = values[i].Value;
if (IsNumericType.IsNumeric(val.GetType()))
    val = values[i].ValueAsDouble();
outputStreamWriter.WriteLine($"{values[i].Timestamp.UtcTime.ToString("o")},{val}");

And added the following class in the same file,

public static class IsNumericType
{
	public static bool IsNumeric(this Type type)
	{
		switch (Type.GetTypeCode(type))
		{
			case TypeCode.Byte:
			case TypeCode.SByte:
			case TypeCode.UInt16:
			case TypeCode.UInt32:
			case TypeCode.UInt64:
			case TypeCode.Int16:
			case TypeCode.Int32:
			case TypeCode.Int64:
			case TypeCode.Decimal:
			case TypeCode.Double:
			case TypeCode.Single:
				return true;
			case TypeCode.Object:
				if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>))
				{
					return Nullable.GetUnderlyingType(type).IsNumeric();
					//return IsNumeric(Nullable.GetUnderlyingType(type));
				}
				return false;
			default:
				return false;
		}
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant