14,244,088 members
Rate this:
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;

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

how can i find the size of double value?

Posted
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.

Rate this:

## Solution 2

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

Or
`int size = de.ToString().Remove(de.ToString().IndexOf('.')).Length;`
v3
VJ Reddy 11-Jun-12 4:09am

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+
Rate this:

## Solution 1

Use this :
```double de = 12345;
int len = (int)Math.Ceiling(Math.Log10(de));```
VJ Reddy 11-Jun-12 4:08am

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!
Member 12925579 28-Dec-16 9:54am

It doesnt work for anything after a decimal point. E.g. 0.2 gives a length of 0.