与float一起使用时,双依赖属性会增加精度

时间:2014-10-15 14:13:12

标签: c# wpf double type-conversion dependency-properties

我为数字编写了自己的输入框。它需要两个限制(最小和最大)并对输入的数字进行一些验证。这两个限制是双依赖属性:

// minimum acepted value
public double Min
{
    get { return (double)GetValue(MinProperty); }
    set { SetValue(MinProperty, value); }
}
public static readonly DependencyProperty MinProperty =
    DependencyProperty.Register("Min", typeof(double), typeof(NumberInputBox), new UIPropertyMetadata(0.0));

一切正常,但当我与float一起使用时,它显示的比我更喜欢。我们可以说0.7显示为0.699999988079071。我怎么能防止这种情况?它适用于intdouble

0 个答案:

没有答案