Click here to Skip to main content
15,888,259 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to find the length of particular double value in C#.

I'm novice, I dont know how to find the length of double value.

For example;

C#
double sample1;
sample1=123;
int size;
size = //size of double value, that is 3.


how can i find the size of double value?

thanks in advance.
Posted
Comments
Rob Philpott 11-Jun-12 3:59am    
By size, do you mean order-of-magnitude or length when expressed as a string? Not that it matters as you have both solutions below.

Use below code:
C#
double sample1;
sample1 = 123;
int size;
size = sample1.ToString().Length;


Or
C#
int size = de.ToString().Remove(de.ToString().IndexOf('.')).Length;
 
Share this answer
 
v3
Comments
VJ Reddy 11-Jun-12 4:09am    
Good answer. 5!
Mehdi Gholam 11-Jun-12 4:26am    
This will only work if the double does not have a decimal point and fractions.
♥…ЯҠ…♥ 11-Jun-12 7:46am    
Thanks dude...!!!
Joezer BH 30-Jun-15 5:43am    
5+
Use this :
C#
double de = 12345;
int len = (int)Math.Ceiling(Math.Log10(de));
 
Share this answer
 
Comments
VJ Reddy 11-Jun-12 4:08am    
Good answer. 5!
Mehdi Gholam 11-Jun-12 4:25am    
Thanks VJ!
♥…ЯҠ…♥ 11-Jun-12 7:46am    
Thanks pal...
Joezer BH 30-Jun-15 5:43am    
5+
Mehdi Gholam 30-Jun-15 5:56am    
Cheers Joezer!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900