459,737 Members | 1,473 Online
Need help? Post your question and get tips & solutions from a community of 459,737 IT Pros & Developers. It's quick & easy.

# Convert double to string

 P: n/a 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 Replies

 P: n/a 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

 P: n/a "Steven" wrote in message news:OD**************@TK2MSFTNGP14.phx.gbl...I have tried to use FormatNumber() to convert a very large double typenumber to String format, however, the result seems not correct, is thereany 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

 P: n/a 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" 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

 P: n/a "Steven" 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

 P: n/a 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" 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" 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 discussion thread is closed

Replies have been disabled for this discussion.