|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Convert double to stringI 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! 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. 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? Show quoteHide quote "Cerebrus" <zorg***@sify.com> wrote in message news:1141278553.857715.178580@p10g2000cwp.googlegroups.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. > "Steven" <a@a.com> wrote in message Declare it as Decimal. All constants should have the D attached. All news:uWdU%23NcPGHA.812@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? variables should be Decimal or be converted to Decimal. 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 Show quoteHide quote "Steven" <a@a.com> schreef in bericht news:uWdU%23NcPGHA.812@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" <zorg***@sify.com> wrote in message > news:1141278553.857715.178580@p10g2000cwp.googlegroups.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. >> > >
Show quote
Hide quote
"Steven" <a@a.com> wrote in message That's a big number for a Double.news:ODujAEbPGHA.2012@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? Dim DecA As Decimal = 999999999999999.12D Dim VarA As String = CStr(DecA) Debug.Print(VarA)
How to put all code generated by the designer in external files (VS2005) ?
Simple Graphics Question Custom DataGRidComboBoxStyle DataSource Problems Fill a tree view with a stored procedure Setting an object to a UserControl .NET 2.0 Conversion Wizard Flags Me.Cursor? How to use a PDB file login/users/roles in ASP.Net? httpwebrequest ASP.Net and Flash |
|||||||||||||||||||||||