format a textbox to remove .000

Hi

I have a textbox that gets assigned qty values but it appears as e.g. 126.000 and would like it to be 126.

any ideas?

Thanks
LVL 1
razza_bAsked:
Who is Participating?
 
KhiluCommented:
Use  following code to make it int and then assign to textbox
int n = Convert.ToInt32(value);

Open in new window


You can directly convert it to string by following code.

 decimal value = 3.14m;
string stringValue = ((int)value).ToString();

Open in new window

0
 
razza_bAuthor Commented:
i have tried converting and doesnt work...

if (dgr.PassQty < Convert.ToInt32(tbWorkOrderQty.Text))
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
KhiluCommented:
Try this

  int thisInt;
            Int32.TryParse(tbWorkOrderQty.Text, out thisInt);
            if (dgr.PassQty < thisInt)
            {
                //Your code
            }

Open in new window

0
 
AndyAinscowFreelance programmer / ConsultantCommented:
How do you assign the value to the textbox ?  (In other words are formatting a string to force it show 3 decimal places in your code ?)

You say textbox.  Do you mean edit OR maskededit box?  A maskededit box has a mask property - which can be set to force decimal places to be shown.
0
 
razza_bAuthor Commented:
simple...

 tbWorkOrderQty.Text = tbWorkOrderQty.Text.Replace(".000", "");
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
Simple - wouldn't it be better to make it work correctly at the start rather than patching it.

ps.  If that works then it isn't a problem with a mask in a maskededit.
0
 
razza_bAuthor Commented:
it always come back with this .000 for every value and the textbox is a readonly so no one can edit it shouyld be fine

but what do you mean by mask edit?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.