How to set masked text box values to decimal numbers?

rangasathish picture rangasathish · Nov 15, 2012 · Viewed 17.3k times · Source

I am new to C# Here i am using masked textbox and set the mask as 00.0. And in database respective field is stored in decimal(3,1) while retrieving to masked text box it will give inaccurate values if i stored 12.3 , 23.8, 45.7 these type of values i got solution But instead of these if we use 1.3 , 3.5, 5.6 i got in my masked text box as 13.0, 35.0, 56.0 .... how to handle this exception? sorry..! for my bad English advance thanks

Answer

Furqan Safdar picture Furqan Safdar · Nov 15, 2012

While setting back the MaskedTextBox, try converting the decimal value according to some format:

maskedTextBox1.Text = value.ToString("0#.#");

This way you will get 01.3 instead of 13.0