Solved

format a textbox to remove .000

Posted on 2013-01-23
8
398 Views
Last Modified: 2013-02-08
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
0
Comment
Question by:razza_b
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 3

Expert Comment

by:Khilu
ID: 38809405
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
 
LVL 1

Author Comment

by:razza_b
ID: 38809492
i have tried converting and doesnt work...

if (dgr.PassQty < Convert.ToInt32(tbWorkOrderQty.Text))
0
 
LVL 3

Expert Comment

by:Khilu
ID: 38809594
Try this

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

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 44

Expert Comment

by:AndyAinscow
ID: 38809617
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
 
LVL 1

Author Comment

by:razza_b
ID: 38809620
simple...

 tbWorkOrderQty.Text = tbWorkOrderQty.Text.Replace(".000", "");
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 38809661
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
 
LVL 1

Author Comment

by:razza_b
ID: 38809689
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
 
LVL 10

Accepted Solution

by:
Monica P earned 500 total points
ID: 38813212
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question