4

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

CRoshanLG
  • 498
  • 1
  • 8
  • 20
rangasathish
  • 595
  • 6
  • 13
  • 25
  • have you tried changing your mask to 0.##? – Adil Mammadov Nov 15 '12 at 06:29
  • i have set the mask as #0.0 and 0.## but it gives the same result. – rangasathish Nov 15 '12 at 06:34
  • I think your question is a very close duplicate of this! --> [winform — Force only numeric values be allowed in maskedtextbox](http://stackoverflow.com/questions/10758683/winform-force-only-numeric-values-be-allowed-in-maskedtextbox) Have a look at this as well --> [Code project Quick Answers](http://www.codeproject.com/Questions/207628/MaskedTextBox-mask-for-decimal-real-float) – CRoshanLG Nov 15 '12 at 07:02

1 Answers1

5

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

Furqan Safdar
  • 16,260
  • 13
  • 59
  • 93
  • may i know what is `value` here? – rangasathish Nov 15 '12 at 06:57
  • i got error like cannot convert from 'string' to 'System.IFormatProvider' – rangasathish Nov 15 '12 at 06:59
  • Assuming value is of type decimal retrieved from the DB. Try converting from Decimal to String. – Furqan Safdar Nov 15 '12 at 07:05
  • On a side note, thank you for flagging low quality answers. If you see something that should be a comment, or link only, could you please flag them as "Not An Answer"? It helps the moderators in that we have other workflow options to make it easier to process these flags. – casperOne Nov 15 '12 at 14:01