hi everyone,
i want to convert a floating point number to an IEEE32 bit standart. first, i tried to split the float number.
here is the code;
float number = float.Parse(Console.ReadLine());
int a = (int)number;
float b= number - a;
Console.WriteLine(a);
Console.WriteLine(b);
but there is a problem, for example i tried to split 12,6 but it splits the number 12 and 0,60000004
how can i fix this problem?
thanks
Loading
nailPosted Mar 23, 2009, 6:47 PM
Thak you so much
aruPosted Mar 23, 2009, 5:13 AM
int a = (int)number;
float
b = (float)Decimal.Subtract((Decimal)number, (Decimal)a); Console.WriteLine(a);Console.WriteLine(b);
Hope this is what you are looking for.
Aleksandar IlioskiPosted Mar 22, 2009, 10:49 PM
double
fBroj;fBroj = 12.356 - 12;
Console.Write(fBroj.ToString("#.##")); // output : ,36;double
fBroj;fBroj = 12.353 - 12;
Console.Write(fBroj.ToString("#.##"));// output: ,35hope this is what you are looking, I thought you want to convert double or float to int not to take the decimal...
nailPosted Mar 22, 2009, 9:44 PM
Aleksandar IlioskiPosted Mar 22, 2009, 8:51 PM
float number = 12.3;
int iNum = Convert.ToInt32(number);
Console.Write(iNum);
Output: 12