Asim
Asim

Reputation: 13

How to convert Decimal in a String Format in XAML WPF?

How i will convert Decimal value in a String Format(Currency) in XAML WPF?

<StackPanel Orientation="Horizontal">
    <TextBlock FontSize="10" Margin="12,2,0,2" Text="$ " />
    <TextBlock FontSize="10" Margin="12,2,0,2" Text="{Binding p_Price}"/> 
 </StackPanel>

//Text="{Binding p_Price, ConverterParameter='0,0.00'}" Not Working

Upvotes: 0

Views: 3717

Answers (2)

Nitin Purohit
Nitin Purohit

Reputation: 18578

You dont need two TextBlocks, use StringFormat to get the currency

<StackPanel Orientation="Horizontal">
    <TextBlock FontSize="10" Margin="12,2,0,2" Text="{Binding p_Price, StringFormat=C}"/> 
 </StackPanel>

Also, your p_Price property should not be of type string.

Upvotes: 2

Noctis
Noctis

Reputation: 11783

As Nit suggested, you can get what you want with the Currency format (C or c).

I suggest you have a look at this MSDN page which has all the references to what you can do with it.

You can specify a number after the c for the amount of digits after the decimal point, and pass the region as well:

123.456 ("C", en-US) -> $123.46

123.456 ("C", fr-FR) -> 123,46 €

123.456 ("C", ja-JP) -> ¥123

-123.456 ("C3", en-US) -> ($123.456)

-123.456 ("C3", fr-FR) -> -123,456 €

-123.456 ("C3", ja-JP) -> -¥123.456

Depending on your needs, N might be useful as well.

Upvotes: 1

Related Questions