473,385 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

trimming left digit of a number

How do I trim the left digit from a number? The user will input a number with
3 digit value and I need to trim the leftmost value from the number. A
typical value might be 123.4567 and I need to remove the 1 and use it's value
in another calculation.

Nov 16 '05 #1
2 5171
If the number is still in textual form you can use string operations:

string leftMostDigit = textualForm.Substring(0, 1);

Even faster is to grab the character:

char leftMostChar = textualForm[0];
int value = leftMostChar - '0';
if ( value < 0 || value > 9 ) { // Error }

If you are working with numbers then I would recommend converting
the item to an integer (trims the decimal locations) and then dividing by
10 until you are left with a value less than 10. Of course if the number is
3 digits, you can divide by 100 after validating the data is greater than
99 and less than 1000.

--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

"Scott" <Sc***@discussions.microsoft.com> wrote in message
news:6E**********************************@microsof t.com...
How do I trim the left digit from a number? The user will input a number with
3 digit value and I need to trim the leftmost value from the number. A
typical value might be 123.4567 and I need to remove the 1 and use it's value
in another calculation.

Nov 16 '05 #2
Justin Rogers wrote:

[...snip...]
If you are working with numbers then I would recommend converting
the item to an integer (trims the decimal locations) and then dividing by
10 until you are left with a value less than 10. Of course if the number is 3 digits, you can divide by 100 after validating the data is greater than
99 and less than 1000.

[...snip...]

Or you might as well use the modulo operator:

123.456 % 100 ==> 23.456
456.789 % 100 ==> 56.789
78 % 100 ==> 78

The % operator is defined for all numeric types.
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: dixie | last post by:
I have been trying to extract the digits between the two / symbols in a date. For example the date (in Australian format, not US) is 23/12/2004. I want to be able to extract the 12 (Month) from...
17
by: Kermit Piper | last post by:
Hello, I have been searching, Googling, searching. Cannot find a javascript to calc 10, 11 or 12 digit UPC codes. I just need an algorithm that calcs to verify the correct check digit. I have...
3
by: Kermit Piper | last post by:
Hello everyone, OK, let me try and explain again please. Here is what I'm trying to do. I have a 12-digit (UPC-A) javascript validation script which works great. All I need now is a similar...
19
by: gk245 | last post by:
I have something like this: printf("Enter numbers: "); scanf ("%i", &number); If the user put in a bunch of numbers (like 4568), instead of just one number, i know that you can extract the...
2
by: hikmaz | last post by:
I am trying to get the rightmost digits (%10) of a number (taken from the user) and store it into successive array locations and get rid of the rightmost digit (\10) to store the next and so on and...
3
by: hl2ob | last post by:
Alright I'm still new to javascript. I was getting it pretty well, and getting everything alright untill this point. We have to make a program that test a 5 digit number as a palindrome. I have no...
7
by: harijay | last post by:
Hi I am a few months new into python. I have used regexps before in perl and java but am a little confused with this problem. I want to parse a number of strings and extract only those that...
5
by: vinod allapu | last post by:
Hi all I have a string like this "2/6/1986" which is a date..Remember that it is a date actually..so day size and month size are variant..It is not always single digit or single character... I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.