You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
|
|
|
|
|
|
namespace GeoSigma.SigmaDrawerStyle.Converter
|
|
|
|
|
|
{
|
|
|
|
|
|
public class DoubleTrimConverter : DoubleConverter
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (destinationType == typeof(string))
|
|
|
|
|
|
{
|
|
|
|
|
|
string strValue = Convert.ToString(value);
|
|
|
|
|
|
int nIndexDot = strValue.IndexOf('.');
|
|
|
|
|
|
if (nIndexDot > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
int nFlag = strValue.IndexOf("0000", nIndexDot);
|
|
|
|
|
|
if (nFlag < 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
nFlag = strValue.IndexOf("9999", nIndexDot);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (nFlag > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
string strFormat = "{0:0.";
|
|
|
|
|
|
for (int i = 0; i < nFlag - nIndexDot - 1; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
strFormat += "#";
|
|
|
|
|
|
}
|
|
|
|
|
|
strFormat += "}";
|
|
|
|
|
|
return string.Format(strFormat, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return Convert.ToString(value);
|
|
|
|
|
|
}
|
|
|
|
|
|
return base.ConvertTo(context, culture, value, destinationType);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|