Link to home
Start Free TrialLog in
Avatar of razza_b
razza_b

asked on

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
Avatar of Khilu
Khilu
Flag of United States of America image

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

Avatar of razza_b
razza_b

ASKER

i have tried converting and doesnt work...

if (dgr.PassQty < Convert.ToInt32(tbWorkOrderQty.Text))
Try this

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

Open in new window

Avatar of AndyAinscow
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.
Avatar of razza_b

ASKER

simple...

 tbWorkOrderQty.Text = tbWorkOrderQty.Text.Replace(".000", "");
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.
Avatar of razza_b

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of Monica P
Monica P
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial