Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format double value in XAML to remove zeros at the end, without scientific representation?

I need to show double values like: 0.00008 in ListView. Unfortunatelly very often values are represented as exponential/scientific: 1E-8. I don't want users to see 1E-8 type values. I don't know and don't want to know decimal points precision of used doubles. I can't round doubles. I can solve this using c#:

string s = doubleValue.ToString("0.####################");  // gives what I need: 0,00008

How to do exactly same formatting using 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>

Or how to do it using c# to assign such formatting to textBlock1 in code behind?

like image 885
as74 Avatar asked Oct 24 '25 18:10

as74


1 Answers

<TextBlock x:Name="textBlock1"
            Text="{Binding Path=Profit,
                          StringFormat={}{0:0.####################}}"
            TextTrimming="CharacterEllipsis" />
like image 166
Viv Avatar answered Oct 26 '25 08:10

Viv



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!