[英]How to format double value in XAML to remove zeros at the end, without scientific representation?
我需要在ListView中显示双精度值:0.00008。 不幸的是,值通常以指数/科学的形式表示:1E-8。 我不希望用户看到1E-8类型值。 我不知道也不想知道二手双精度小数点的精度。 我不能双打。 我可以使用C#解决此问题:
string s = doubleValue.ToString("0.####################"); // gives what I need: 0,00008
如何使用xaml进行完全相同的格式化?
<ListView.View>
<GridView AllowsColumnReorder="False">
<GridView.Columns>
<GridViewColumn.CellTemplate>
<DataTemplate>
<Border>
<Grid>
<TextBlock x:Name="textBlock1" Text="{Binding Path=Profit, StringFormat={{???}}" TextTrimming="CharacterEllipsis" />
</Grid>
</Border>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridView.Columns>
</GridView>
</ListView.View>
或者如何使用c#在后面的代码中将这种格式分配给textBlock1呢?
<TextBlock x:Name="textBlock1"
Text="{Binding Path=Profit,
StringFormat={}{0:0.####################}}"
TextTrimming="CharacterEllipsis" />
在许多情况下,获得这些数字的原因是因为您实际上应该使用小数而不是双精度。 如果使用双精度进行计算,通常会得到很小的十进制错误,可以很容易避免。
尝试这个:
Text="{Binding Profit, StringFormat='0.00000'}"
尝试使用StringFormat = F6之类的格式,将您的数字格式化为6位小数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.