convert int to string?

  • Thread starter Thread starter Darryn Ross
  • Start date Start date
D

Darryn Ross

Hi,

I am trying to convert an integer into a string but when i do i loose some
of the integer... e.g

int i = 10.00 ;
string s ;

s = Convert.ToString(i) ;

s = "10" not "10.00"

how do i get the string to look like this "10.00"??

Thanks
 
Hi,

Integer doesn't have any decimal point you need a float or double, when
you declare int i = 10.00; it will be converted to int i = 10.

Regards,
Emad
 
This seems a bit corny but here's a workaround:

float f = 10.001f;
MessageBox.Show(f.ToString().Substring(0,5));
 
sorry made a typo....

the problem is the same anyway!!

double i = 10.00 ;
string s ;

s = Convert.ToString(i) ;

s = "10" not "10.00"

how do i get the string to look like this "10.00"??

Thanks
 
Darryn said:
Hi,

I am trying to convert an integer into a string but when i do i loose some
of the integer... e.g

int i = 10.00 ;
string s ;

s = Convert.ToString(i) ;

s = "10" not "10.00"

how do i get the string to look like this "10.00"??

Thanks

class Test
{
static void Main()
{
double d=10.00;
System.Console.WriteLine("d="+d.ToString("#.00"));
// or
String s = d.ToString("#.00");
}
}

David Logan
 
sorry made a typo....

the problem is the same anyway!!

double i = 10.00 ;
string s ;

s = Convert.ToString(i) ;

s = "10" not "10.00"

how do i get the string to look like this "10.00"??

Thanks

s = i.ToString("F2");

Oz
 
thankz!

ozbear said:
s = i.ToString("F2");

Oz
--
A: Because it fouls the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
 
Hi there,

You can do this:

double i = 10.00;
Console.WriteLine(string.Format("{0:f}", i));

Output: 10.00

OR

double i = 10.006887;
Console.WriteLine(string.Format("{0:0.000}", i));

Output: 10.007

Coz integer can never accepts 10.00. Correct me if i am wrong.

Thanks.
 
Back
Top