Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore integer start with 0

Tags:

c#

asp.net

I am working on a web application. I have two text boxes, one is txtEmployeeID, and one is txtEmployeeName. What I am trying to do here is when the user enter EmployeeID in the txtEmployeeID, the name of the employee will show up in the txtEmployeeName. I got this part working so far. However, if the employeeID start with bunch of 0, let say 00000345, the user need to enter all 00000345 in the employeeID in order to show that employeeName. I am wondering if there a way for user to just enter 345 and then that 00000345's employeeName will display in the txtEmployeeName? Help will be appreaciated.

For Example

EmployeeID   EmployeeName
00000345     James Murray

In my text box.

Employee ID: 345   

It will display

Employee Name: James Murray

My DB Query

@Employee_ID    varchar(8) = NULL

SELECT s.Employee_ID, p.FIRST_NAME, p.LAST_NAME
    FROM [dbo].[Employee] e INNER JOIN [dbo].[Person] p ON e.PERSON_ID = p.PERSON_ID
    WHERE p.Employee_ID = @Employee_ID
like image 220
RedRocket Avatar asked Nov 26 '15 08:11

RedRocket


People also ask

Can an Integer start with 0?

Zeros are ignored at the start of an int . If you need the zeros to be displayed, store the number as a String instead. If you need to use it for calculations later, you can convert it to an int using Integer.

How do I ignore a number in C++?

The cin. ignore() function is used which is used to ignore or clear one or more characters from the input buffer.

How do I get rid of .0 in Python?

Use str. Call str. strip(chars) on a string with "0" as chars to remove zeros from the beginning and end of the string.


2 Answers

Try this

int num = Convert.ToInt32(txtEmployeeID.Text);
string idNum = num.ToString("00000000");
txtEmployeeID.Text = idNum.ToString();
like image 57
odlan yer Avatar answered Sep 22 '22 02:09

odlan yer


You can use Int32.ToString("000") to format an integer in this manner. For details, see Custom Numeric Format Strings and Int32.ToString:

txtEmployeeID.text.ToString("00000000") == EmployeeID;

like image 32
do_Ob Avatar answered Sep 19 '22 02:09

do_Ob