Solved

format a textbox to remove .000

Posted on 2013-01-23
8
395 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
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…

770 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