# double variable help needed

• ### Question

• hello

i have double value  froexampl

25.37

i want to save it 25 in interger variable

i want to save it .37 in double

It's Me
Thursday, May 27, 2010 6:12 AM

### All replies

• Simple way using string operation

```double d = 25.37;

string[] parts = d.ToString().Split(".".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

int value = int.Parse(parts[0]);
float value1 = float.Parse("0."+parts[1]);```

 Thanks, A.m.a.L [MVP Visual C#] Dot Net Goodies Don't hate the hacker, hate the code
Thursday, May 27, 2010 6:36 AM
• ```      double x = 25.32;
int y = Convert.ToInt32(x);
double z = (x - y) ;```
Thursday, May 27, 2010 6:38 AM
• Hi,

```      double d = 25.37;
int i = (int)Math.Floor(d);
double d2 = (double)(Convert.ToDecimal(d) - i);```

Sincerely,

Yasser

WHAT'S NEW IN THE .NET FRAMEWORK 4:
Article: Comparison of parallel and sequential computing in .NET Framework
Thursday, May 27, 2010 6:38 AM
• ```   double

x = 25.32;
int

y = Convert.ToInt32(x);
double

z = (x - y) ;
```

Hi Ahmed,

Just a screen shot of my output window

 Thanks, A.m.a.L [MVP Visual C#] Dot Net Goodies Don't hate the hacker, hate the code
Thursday, May 27, 2010 6:43 AM
• And if negative numbers are possible:
```      double d = -25.37;
int i = (d > 0 ? (int)Math.Floor(d) : (int)Math.Ceiling(d));
double d2 = (double)(Convert.ToDecimal(d) - i);
```

WHAT'S NEW IN THE .NET FRAMEWORK 4:
Article: Comparison of parallel and sequential computing in .NET Framework
• Marked as answer by Thursday, May 27, 2010 9:11 AM
Thursday, May 27, 2010 6:50 AM
• Ooops, forgot about that :)
Thursday, May 27, 2010 7:22 AM