473,387 Members | 1,606 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 double to string

I have tried to use FormatNumber() to convert a very large double type
number to String format, however, the result seems not correct, is there any
limitation for using FormatNumber() function?

For example, I write the code shown below:
Dim DblA as double = 999999999999999.12
Dim VarA As String = FormatNumber(DblA)

The result of VarA contains value "999999999999999.00" instead of
"999999999999999.12".

I have also tried to use CStr(), It's also not work.

So I want to ask if there any method to convert a large double number to
string format?

Thanks!
Mar 2 '06 #1
5 36770
Hi Steven,

It sure works if you use a Decimal data type instead of Double. Another
point is that you need to force the value to be of that particular
type, by using a character literal (R for Double and D for Decimal)

Dim DblA As Decimal = 999999999999999.12D
Dim VarA As String = CStr(DblA)
Console.WriteLine(VarA)

Regards,

Cerebrus.

Mar 2 '06 #2

"Steven" <a@a.com> wrote in message
news:OD**************@TK2MSFTNGP14.phx.gbl...
I have tried to use FormatNumber() to convert a very large double type
number to String format, however, the result seems not correct, is there
any limitation for using FormatNumber() function?

For example, I write the code shown below:
Dim DblA as double = 999999999999999.12
Dim VarA As String = FormatNumber(DblA)

The result of VarA contains value "999999999999999.00" instead of
"999999999999999.12".

I have also tried to use CStr(), It's also not work.

So I want to ask if there any method to convert a large double number to
string format?


That's a big number for a Double.

Dim DecA As Decimal = 999999999999999.12D

Dim VarA As String = CStr(DecA)

Debug.Print(VarA)


Mar 2 '06 #3
What if the large decimal value is not a static value but calcuated by a
complex formula instead?

How can I force the output value to be that particular type just like adding
a "D" at the end of the static value?
"Cerebrus" <zo*****@sify.com> wrote in message
news:11**********************@p10g2000cwp.googlegr oups.com...
Hi Steven,

It sure works if you use a Decimal data type instead of Double. Another
point is that you need to force the value to be of that particular
type, by using a character literal (R for Double and D for Decimal)

Dim DblA As Decimal = 999999999999999.12D
Dim VarA As String = CStr(DblA)
Console.WriteLine(VarA)

Regards,

Cerebrus.

Mar 2 '06 #4

"Steven" <a@a.com> wrote in message
news:uW***************@TK2MSFTNGP10.phx.gbl...
What if the large decimal value is not a static value but calcuated by a
complex formula instead?

How can I force the output value to be that particular type just like
adding a "D" at the end of the static value?


Declare it as Decimal. All constants should have the D attached. All
variables should be Decimal or be converted to Decimal.

Mar 2 '06 #5
Steven,

You can use the very strong Visual Basic convert methods one of those is

CDec(1234*1234)

Be aware that Net 1.x uses the seldom used Bankers Rounding

I hope this helps,

Cor

"Steven" <a@a.com> schreef in bericht
news:uW***************@TK2MSFTNGP10.phx.gbl...
What if the large decimal value is not a static value but calcuated by a
complex formula instead?

How can I force the output value to be that particular type just like
adding a "D" at the end of the static value?
"Cerebrus" <zo*****@sify.com> wrote in message
news:11**********************@p10g2000cwp.googlegr oups.com...
Hi Steven,

It sure works if you use a Decimal data type instead of Double. Another
point is that you need to force the value to be of that particular
type, by using a character literal (R for Double and D for Decimal)

Dim DblA As Decimal = 999999999999999.12D
Dim VarA As String = CStr(DblA)
Console.WriteLine(VarA)

Regards,

Cerebrus.


Mar 2 '06 #6

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

Similar topics

1
by: lbzheng | last post by:
I want to convert a string(example "3.1415") to double. Are there function do it in c/c++ library ? thanks, lokicer
3
by: jeff_zhang446 | last post by:
Hi, I try to convert double to string as below: std::string cnvrtToString(double lValue) { std::ostringstream lStream; lStream << lValue; return lStream.str();
4
by: joe_rattz | last post by:
I need to convert a text string ("Dewey & Cheatham & Howe") to an XML encoded string ("Dewey &amp; Cheatham &amp; Howe"). I am not building an XML document, I am just trying to convert a single string. I...
12
by: Alan | last post by:
how to convert double to short ? for example, I want to convert double doubleVal1 = 15000.1; double doubleVal2 = 12000.0; short shortVal; shortVal = doubleVal1 - doubleVal2; I...
4
by: STom | last post by:
How do you convert a string in C# to decimal? STom
2
by: Laurence | last post by:
I want to convert a double value to string. 1.2345678911 -> "1.234567891" 123 -> "123" I used the following code to convert it: string str = doubleValue.ToString("f9"); but the second...
6
by: Mark Chimes | last post by:
Hi All, I need to search thru some strings and discard them if they canot be converted to a decimal or interger value. What is the best way to do this? cheers, Mark Chimes
8
by: shiniskumar | last post by:
Ive got a double variable dTotal =5.037717235E7 i formatted it using deciFormat.format(dTotal) and got the String value of dTotal=50377172.35 now i have to pass this value as an argument to a...
1
by: niharnayak2003 | last post by:
Hi All, I am facing the problem in Typecast inside the Generic class. I need a function which will take two param 1:-Xpath 2:- XMLDOC and return me what i will need. here is the code for...
1
by: Bjorn Brox | last post by:
Hi! In germany, norway and France(?) we are using ',' as decimal separator and it always messes up when you convert a double to and from a string where the interface expects double values stored...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.