科学记谱法XAML

时间:2012-06-28 14:56:33

标签: xaml silverlight-5.0 scientific-notation

我在XAML中使用科学记数法。我这样做:

<TextBox Text="{Binding Path=CELULARIDAD_CFU, StringFormat='e6'}"/>

问题是1710000显示:1.710000e + 006,这是正确的,但我想看到1.71e + 6。这是如何在XAML中指定的? (不在代码中)

2 个答案:

答案 0 :(得分:1)

我相信你应该使用G format specifier来获得(几乎)你想要的东西。

<TextBox Text="{Binding Path=CELULARIDAD_CFU, StringFormat='G'}"/>

在一定范围内(不同数字类型不同,请参阅链接),该数字将以正常表示法显示。对于大到或足够小的值,将显示的值不带尾随零和2个指数位。

float的示例:

1340000  => 1340000
13400000 => 1.34e+07
0.00054  => 0.00054
0.000054 => 5.4e-05

答案 1 :(得分:1)

我没找到我想要的东西所以我决定使用IValueConverter。例如:

Public Class scientificNotation6
    Implements IValueConverter

    Const EXP As Double = 1000000
    Public Function Convert(value As Object, targetType As System.Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
        Return CDbl(value) / EXP 'whatever you want
    End Function

    Public Function ConvertBack(value As Object, targetType As System.Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
        Return CDbl(value) * EXP 'whatever you want
    End Function
End Class

然后在XAML页面中:

<TextBox Text="{Binding Path=CELULARIDAD_CONGELADO, Converter={StaticResource scientificNotation6}"/>

我希望它有所帮助。

相关问题