473,387 Members | 1,486 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

convert int to string?

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
Nov 16 '05 #1
7 17701
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

"Darryn Ross" <da****@datawave.com.au> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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

Nov 16 '05 #2
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
"Emad Barsoum" <e_*******@hotmail.com> wrote in message
news:Ou*************@TK2MSFTNGP12.phx.gbl...
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

"Darryn Ross" <da****@datawave.com.au> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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


Nov 16 '05 #3
This seems a bit corny but here's a workaround:

float f = 10.001f;
MessageBox.Show(f.ToString().Substring(0,5));
"Darryn Ross" wrote:
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

Nov 16 '05 #4
Darryn Ross wrote:
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
Nov 16 '05 #5
On Wed, 30 Jun 2004 12:41:25 +1000, "Darryn Ross"
<da****@datawave.com.au> wrote:
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
--
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?
Nov 16 '05 #6
thankz!

"ozbear" <oz****@bigpond.com> wrote in message
news:40e2371a.1279359453@news-server...
On Wed, 30 Jun 2004 12:41:25 +1000, "Darryn Ross"
<da****@datawave.com.au> wrote:
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
--
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?

Nov 16 '05 #7
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.
--
Regards,
Chua Wen Ching :)
"David Logan" wrote:
Darryn Ross wrote:
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

Nov 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Joel Moore | last post by:
Maybe I'm just easily baffled after an all-nighter but I can't seem to figure out how to represent a BitArray as a hexadecimal string. For example: Dim outputBank As New BitArray(8) ...
4
by: Eric Lilja | last post by:
Hello, I've made a templated class Option (a child of the abstract base class OptionBase) that stores an option name (in the form someoption=) and the value belonging to that option. The value is...
4
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
3
by: Convert TextBox.Text to Int32 Problem | last post by:
Need a little help here. I saw some related posts, so here goes... I have some textboxes which are designed for the user to enter a integer value. In "old school C" we just used the atoi function...
7
by: patang | last post by:
I want to convert amount to words. Is there any funciton available? Example: $230.30 Two Hundred Thirty Dollars and 30/100
6
by: patang | last post by:
Could someone please tell me where am I supposed to put this code. Actually my project has two forms. I created a new module and have put the following code sent by someone. All the function...
3
by: GM | last post by:
Dear all, Could you all give me some guide on how to convert my big5 string to unicode using python? I already knew that I might use cjkcodecs or python 2.4 but I still don't have idea on what...
4
by: tshad | last post by:
I am trying to convert a string character to an int where the string is all numbers. I tried: int test; string stemp = "5"; test = Convert.ToInt32(stemp); But test is equal to 53.
9
by: Marco Nef | last post by:
Hi there I'm looking for a template class that converts the template argument to a string, so something like the following should work: Convert<float>::Get() == "float"; Convert<3>::Get() ==...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.