2

I am working on Windows Phone Application.

I need to concat two values which are integers and the result should be changed into float value.

For example, a = 120 and b = 3. Then result c = 120.3 which is float value. How to do this task?

Adel Khayata
  • 2,717
  • 10
  • 28
  • 46
madhu kumar
  • 786
  • 1
  • 12
  • 46

5 Answers5

4
 int a = 120;
 int b = 3;
 string s = a + "." + b;
 float f = float.Parse(s);
Prabhakaran Parthipan
  • 4,193
  • 2
  • 18
  • 27
3

How about using float.Parse?

float value = float.Parse(string.Format("{0}.{1}", a.ToString(), b.ToString()));
MarcinJuraszek
  • 124,003
  • 15
  • 196
  • 263
1

You can try this sample code:

int a = 120;
int b = 3;
string c = a.ToString() + '.' + b.ToString();
float f = float.Parse(c,System.Globalization.CultureInfo.InvariantCulture);
Alex
  • 5,971
  • 11
  • 42
  • 80
1

How about using this shorter one:

float f = float.Parse(string.Concat(a, ".", b));
Sunny Sharma
  • 4,688
  • 5
  • 35
  • 73
0

I would do is: dim FB = B * 0.1, C = A + FB as Float or as each part as string and S for string on your variables SC = SA +"." +SB And convert string to value this logic should work in most versions of C and BASIC and most likely other languages too

peace
  • 29
  • 1
  • 6