Posts

Showing posts from May, 2018

UWP: Displaying formatted text in a TextBox Control

Image
The entry you make in a text box control is of data type text and sometimes you need to format it as a currency with thousands separator while displaying. Also, if the number of decimal places you enter is more than 2, you need to round it up to 2 in the output. How do you code this in a UWP app? Create a UWP page starting from a Blank UWP project with three controls as shown. There are two text boxes and a button. You enter a number in the top textbox (txt1) and click the button, the formatted currency will be displayed in the bottom textbox(txt2). The app displays as shown. Now provide for a click event for the button and insert code as shown: Convert_1 The string entered in txt1 is converted to data-type double, it is then 'rounded'. The rounded number is then formatted to show the currency symbol and the 1000's place delimiter you find, for example in Excel formatting. Here is the app after entering a number and c