473,383 Members | 1,759 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,383 software developers and data experts.

Length of digit after decimal point

Hey there,

Anyone knows a clever method for knowing the length of the digit after
a decimal point in a standard C# decimal value, WITHOUT use of any
string formatting.

Example:
5231,12231 <- Lengt = 5

Tnx for your attention hope you are capable of helping.

Kind regards
Stefan

Nov 14 '06 #1
5 2924
You could just split it apart, without any formatting

Double start_value = 5231.12231;
string[] end_values = start_value.ToString().Split('.');
int slen = end_values[1].Length;
Response.Write(slen);

--
Regards

John Timney (MVP)
VISIT MY WEBSITE:
http://www.johntimney.com
http://www.johntimney.com/blog
"Stefantastisk" <st***********@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
Hey there,

Anyone knows a clever method for knowing the length of the digit after
a decimal point in a standard C# decimal value, WITHOUT use of any
string formatting.

Example:
5231,12231 <- Lengt = 5

Tnx for your attention hope you are capable of helping.

Kind regards
Stefan

Nov 14 '06 #2
Hey John,

Tnx for your reaction.

Your example is one of the most slick methods, that I also have
considered, but there is still a ToString formatting going on.

BUT it seems as, according to reactions in other groups, that it is
nearly impossible to avoid the use of string formatting.

My worries towards the use of string formatting is based on the
differences in cultural string handling and the formatting of decimals
("," or ".").

But thanks for your example.

Take care

Regards,
Stefan

On 14 Nov., 16:18, "John Timney \(MVP\)" <x_j...@timney.eclipse.co.uk>
wrote:
You could just split it apart, without any formatting

Double start_value = 5231.12231;
string[] end_values = start_value.ToString().Split('.');
int slen = end_values[1].Length;
Response.Write(slen);

--
Regards

John Timney (MVP)
VISIT MY WEBSITE:http://www.johntimney.comhttp://www.johntimney.com/blog

"Stefantastisk" <stefantast...@gmail.comwrote in messagenews:1163514310..89***********@b28g2000cwb. googlegroups.com...
Hey there,
Anyone knows a clever method for knowing the length of the digit after
a decimal point in a standard C# decimal value, WITHOUT use of any
string formatting.
Example:
5231,12231 <- Lengt = 5
Tnx for your attention hope you are capable of helping.
Kind regards
Stefan- Skjul tekst i anførselstegn -- Vis tekst i anførselstegn -
Nov 15 '06 #3
The problem is your asking for a count of the number of integers, in theory
your asking for the length of a set of characters. The fact that they are
numbers is irrelevent really.

Heres an example that doesn't care about whether the seperator is . or , or
whatever, but instead assumes that the first none numeric character of the
string in reverse is the seperator, and thus concludes the char count.

Double myVal = 5231.12231;
char[] reverse = myVal.ToString().ToCharArray();
Array.Reverse(reverse);
for (int i = 0; i < reverse.Length; i++){
if (!char.IsNumber(reverse[i])){
Response.Write("Length is " + i);
}
}

--
--
Regards

John Timney (MVP)
VISIT MY WEBSITE:
http://www.johntimney.com
http://www.johntimney.com/blog

"Stefantastisk" <st***********@gmail.comwrote in message
news:11**********************@h54g2000cwb.googlegr oups.com...
Hey John,

Tnx for your reaction.

Your example is one of the most slick methods, that I also have
considered, but there is still a ToString formatting going on.

BUT it seems as, according to reactions in other groups, that it is
nearly impossible to avoid the use of string formatting.

My worries towards the use of string formatting is based on the
differences in cultural string handling and the formatting of decimals
("," or ".").

But thanks for your example.

Take care

Regards,
Stefan

On 14 Nov., 16:18, "John Timney \(MVP\)" <x_j...@timney.eclipse.co.uk>
wrote:
You could just split it apart, without any formatting

Double start_value = 5231.12231;
string[] end_values = start_value.ToString().Split('.');
int slen = end_values[1].Length;
Response.Write(slen);

--
Regards

John Timney (MVP)
VISIT MY WEBSITE:http://www.johntimney.comhttp://www.johntimney.com/blog

"Stefantastisk" <stefantast...@gmail.comwrote in
messagenews:11**********************@b28g2000cwb.g ooglegroups.com...
Hey there,
Anyone knows a clever method for knowing the length of the digit after
a decimal point in a standard C# decimal value, WITHOUT use of any
string formatting.
Example:
5231,12231 <- Lengt = 5
Tnx for your attention hope you are capable of helping.
Kind regards
Stefan- Skjul tekst i anførselstegn -- Vis tekst i anførselstegn -

Nov 15 '06 #4
Hey John,

Nice snippet of code, that is a clever design regarding the
delimiter/culture issue.

Tnx mate.

Regards
Stefan

On 15 Nov., 12:54, "John Timney \(MVP\)" <x_j...@timney.eclipse.co.uk>
wrote:
The problem is your asking for a count of the number of integers, in theory
your asking for the length of a set of characters. The fact that they are
numbers is irrelevent really.

Heres an example that doesn't care about whether the seperator is . or , or
whatever, but instead assumes that the first none numeric character of the
string in reverse is the seperator, and thus concludes the char count.

Double myVal = 5231.12231;
char[] reverse = myVal.ToString().ToCharArray();
Array.Reverse(reverse);
for (int i = 0; i < reverse.Length; i++){
if (!char.IsNumber(reverse[i])){
Response.Write("Length is " + i);
}
}

--
--
Regards

John Timney (MVP)
VISIT MY WEBSITE:http://www.johntimney.comhttp://www.johntimney.com/blog

"Stefantastisk" <stefantast...@gmail.comwrote in messagenews:1163577586..75***********@h54g2000cwb. googlegroups.com...
Hey John,

Tnx for your reaction.

Your example is one of the most slick methods, that I also have
considered, but there is still a ToString formatting going on.

BUT it seems as, according to reactions in other groups, that it is
nearly impossible to avoid the use of string formatting.

My worries towards the use of string formatting is based on the
differences in cultural string handling and the formatting of decimals
("," or ".").

But thanks for your example.

Take care

Regards,
Stefan

On 14 Nov., 16:18, "John Timney \(MVP\)" <x_j...@timney.eclipse.co.uk>
wrote:
You could just split it apart, without any formatting
Double start_value = 5231.12231;
string[] end_values = start_value.ToString().Split('.');
int slen = end_values[1].Length;
Response.Write(slen);
--
Regards
John Timney (MVP)
VISIT MY WEBSITE:http://www.johntimney.comhttp://www.johntimney.com/blog
"Stefantastisk" <stefantast...@gmail.comwrote in
messagenews:11**********************@b28g2000cwb.g ooglegroups.com...
Hey there,
Anyone knows a clever method for knowing the length of the digit after
a decimal point in a standard C# decimal value, WITHOUT use of any
string formatting.
Example:
5231,12231 <- Lengt = 5
Tnx for your attention hope you are capable of helping.
Kind regards
Stefan- Skjul tekst i anførselstegn -- Vis tekst i anførselstegn -- Skjul tekst i anførselstegn -- Vis tekst i anførselstegn -
Nov 22 '06 #5
glad you like it

--
--
Regards

John Timney (MVP)
VISIT MY WEBSITE:
http://www.johntimney.com
http://www.johntimney.com/blog
"Stefantastisk" <st***********@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Hey John,

Nice snippet of code, that is a clever design regarding the
delimiter/culture issue.

Tnx mate.

Regards
Stefan

On 15 Nov., 12:54, "John Timney \(MVP\)" <x_j...@timney.eclipse.co.uk>
wrote:
The problem is your asking for a count of the number of integers, in
theory
your asking for the length of a set of characters. The fact that they are
numbers is irrelevent really.

Heres an example that doesn't care about whether the seperator is . or ,
or
whatever, but instead assumes that the first none numeric character of the
string in reverse is the seperator, and thus concludes the char count.

Double myVal = 5231.12231;
char[] reverse = myVal.ToString().ToCharArray();
Array.Reverse(reverse);
for (int i = 0; i < reverse.Length; i++){
if (!char.IsNumber(reverse[i])){
Response.Write("Length is " + i);
}
}

--
--
Regards

John Timney (MVP)
VISIT MY WEBSITE:http://www.johntimney.comhttp://www.johntimney.com/blog

"Stefantastisk" <stefantast...@gmail.comwrote in
messagenews:11**********************@h54g2000cwb.g ooglegroups.com...
Hey John,

Tnx for your reaction.

Your example is one of the most slick methods, that I also have
considered, but there is still a ToString formatting going on.

BUT it seems as, according to reactions in other groups, that it is
nearly impossible to avoid the use of string formatting.

My worries towards the use of string formatting is based on the
differences in cultural string handling and the formatting of decimals
("," or ".").

But thanks for your example.

Take care

Regards,
Stefan

On 14 Nov., 16:18, "John Timney \(MVP\)" <x_j...@timney.eclipse.co.uk>
wrote:
You could just split it apart, without any formatting
Double start_value = 5231.12231;
string[] end_values = start_value.ToString().Split('.');
int slen = end_values[1].Length;
Response.Write(slen);
--
Regards
John Timney (MVP)
VISIT MY WEBSITE:http://www.johntimney.comhttp://www.johntimney.com/blog
"Stefantastisk" <stefantast...@gmail.comwrote in
messagenews:11**********************@b28g2000cwb.g ooglegroups.com...
Hey there,
Anyone knows a clever method for knowing the length of the digit after
a decimal point in a standard C# decimal value, WITHOUT use of any
string formatting.
Example:
5231,12231 <- Lengt = 5
Tnx for your attention hope you are capable of helping.
Kind regards
Stefan- Skjul tekst i anførselstegn -- Vis tekst i anførselstegn --
Skjul tekst i anførselstegn -- Vis tekst i anførselstegn -

Nov 22 '06 #6

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

Similar topics

26
by: Adrian Parker | last post by:
I'm using the code below in my project. When I print all of these fixed length string variables, one per line, they strings in questions do not properly pad with 0s. strQuantity prints as " ...
3
by: mrstephengross | last post by:
Hi all... How can I find out the number of significant digits (to the right of the decimal place, that is) in a double? At least, I *think* that's what I'm asking for. For instance: 0.103 -->...
4
by: nate | last post by:
Hey everyone, I am trying to figure out what is the largest integer I can. Lets say for 400 megabytes of memory at my disposal. I have tried a few things c = 2**1000000 d = 2**2000000 print...
8
by: Candace | last post by:
I am using the following code to pick off each digit of a number, from right to left. The number I am working with is 84357. So for the first iteration it should return the number 7 and for the...
7
by: Stefantastisk | last post by:
Hey there, Anyone knows a clever method for knowing the length of the digit after a decimal point in a standard C# decimal value, WITHOUT use of any string formatting. Example: 5231,12231 <-...
13
by: Shirsoft | last post by:
I have a 32 bit intel and 64 bit AMD machine. There is a rounding error in the 8th digit. Unfortunately because of the algorithm we use, the errors percolate into higher digits. C++ code is...
7
by: Jay | last post by:
I want to check if a character is a decimal digit (0-9). I've found Char.IsNumber() and Char.IsDigit() but couldn't work out from Help how they differ. Also, do I need to worry about how digits...
2
by: Nasir Rehaman | last post by:
Salam i want to display numbers with only two digit after decimal point using c#, but coud'nt success.Please any body help me.
8
by: Marc | last post by:
Hi all, I have to generate and send to a printer many 6 digit alphanumeric strings. they have to be unique but I cannot check in a database or something like that if it have already been printed....
2
by: Jcan | last post by:
HI I have a 10 digit ASCII array: char Arr = {'1','2','3','4','5','6','7','8','9','1'} I have to convert the the array to decimal. I do this by subtracting 0x30 and multiplying with...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.