How to Format a Number in a C# WPF Binding

How to Format a Number in a C# WPF Binding

No Comments on How to Format a Number in a C# WPF Binding

A number can be formatted in a XAML binding. The following GridViewColumn will be formatted to currency with two decimal points and a currency symbol:

DisplayMemberBinding="{Binding Amount, StringFormat=C}"

There are many formatters available for example:

DisplayMemberBinding="{Binding Amount, StringFormat=N2}"

This would format the number to two decimal places without the currency symbol.

About the author:

Bill Payne started working as a paid professional software developer at the young age of 12 years old developing simple games and other applications for pre-packaged computers. Bill has since developed software for many industries such as direct sales and the the stock market. Bill has now started sharing his many years of software development experience through a blog on the MPSHouse website and one on one lessons.

Leave a comment

Back to Top