displaying numbers in correct format in textbox C#
the number entered in the textbox is stored as integer,suppose if you enter a number like 0095 on exiting textbox it should displayed "95",also another textbox takes float,if i enter 1.567 it should be displayed as"1.5"...how to开发者_开发知识库 do that in C#?
Like most other languages I assume. In C# when I do something like that, I get the data from the textbox,usually richtextbox, store it as a string. from there you can typecast it to an int (should you believe that what is being typed is an int) and then do a fairly straight forward trim of the float number.
Use readline to take lines as strings, or just take the whole thing as a string, depending on how you implement it.
Convert strings to ints using:
int numVal = Int32.Parse("105");
or
string text = "500";
int num = int.Parse(text);
and then
Math.Round(float,decimals)
for trimming the float.
精彩评论