444,168 Members | 2,598 Online
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,168 IT Pros & Developers. It's quick & easy.

# format a "numeric" string

 P: n/a How can I format a string like this: 12924.999999999999 to print 12,925 ? Nov 20 '05 #1
9 Replies

 P: n/a Convert your string to a double, and then convert it back to a string. I use the following code to convert doubles to string: Dim value as double Dim result As String Dim nfi As NumberFormatInfo nfi = New CultureInfo("en-US", False).NumberFormat nfi.NumberDecimalSeparator = "." 'set the decimal sep. nfi.NumberGroupSeparator = "," 'set de grup sep. nfi.NumberDecimalDigits = "0" 'set the number of decim. result = value.ToString("N", nfi) Try it out! -----Original Message-----How can I format a string like this: 12924.999999999999to print 12,925 ? . Nov 20 '05 #2

 P: n/a MsgBox(Math.Round(12924.999999999998)) OHM rocio wrote: How can I format a string like this: 12924.999999999999 to print 12,925 ? -- Best Regards - OHM O_H_M{at}BTInternet{dot}com Nov 20 '05 #3

 P: n/a or ( having read this again ) MsgBox(Math.Round( Cdbl("12924.999999999998"))) Regards - OHM One Handed Man [ OHM# ] wrote: MsgBox(Math.Round(12924.999999999998)) OHM rocio wrote: How can I format a string like this: 12924.999999999999 to print 12,925 ? -- Best Regards - OHM O_H_M{at}BTInternet{dot}com Nov 20 '05 #4

 P: n/a yes, it works. Tx! "BeGomes" wrote in message news:00****************************@phx.gbl... Convert your string to a double, and then convert it back to a string. I use the following code to convert doubles to string: Dim value as double Dim result As String Dim nfi As NumberFormatInfo nfi = New CultureInfo("en-US", False).NumberFormat nfi.NumberDecimalSeparator = "." 'set the decimal sep. nfi.NumberGroupSeparator = "," 'set de grup sep. nfi.NumberDecimalDigits = "0" 'set the number of decim. result = value.ToString("N", nfi) Try it out! -----Original Message-----How can I format a string like this: 12924.999999999999to print 12,925 ? . Nov 20 '05 #5

 P: n/a You can also just use String.Format "rocio" wrote in message news:uD**************@TK2MSFTNGP09.phx.gbl... How can I format a string like this: 12924.999999999999 to print 12,925 ? Nov 20 '05 #6

 P: n/a I 'Allways' f&*%Łng forget that Regards - OHM CJ Taylor wrote: You can also just use String.Format "rocio" wrote in message news:uD**************@TK2MSFTNGP09.phx.gbl... How can I format a string like this: 12924.999999999999 to print 12,925 ? -- Best Regards - OHM O_H_M{at}BTInternet{dot}com Nov 20 '05 #7

 P: n/a hehe I love string.format... If .NET gave me nothing else, it gave me that... =) "One Handed Man [ OHM# ]" wrote in message news:Oj**************@TK2MSFTNGP12.phx.gbl... I 'Allways' f&*%Łng forget that Regards - OHM CJ Taylor wrote: You can also just use String.Format "rocio" wrote in message news:uD**************@TK2MSFTNGP09.phx.gbl... How can I format a string like this: 12924.999999999999 to print 12,925 ? -- Best Regards - OHM O_H_M{at}BTInternet{dot}com Nov 20 '05 #8

 P: n/a Rocio, In addition to the other comments you can also use Double.ToString(). Both ToString & String.Format support different format strings. Note if you come from a VB6 background Format is still supported, however I tend to use the .NET equivalents, as the .NET usage applies to more places in the Framework! (String.Format, StringBuilder.AppendFormat, Object.ToString, Console.Write, StreamWriter.Write...) For details on formatting in .NET see: http://msdn.microsoft.com/library/de...ttingtypes.asp For numerics see: http://msdn.microsoft.com/library/de...matstrings.asp For VB.NET runtime support see: http://msdn.microsoft.com/library/de...afctFormat.asp http://msdn.microsoft.com/library/de...rmatNumber.asp Hope this helps Jay "rocio" wrote in message news:uD**************@TK2MSFTNGP09.phx.gbl... How can I format a string like this: 12924.999999999999 to print 12,925 ? Nov 20 '05 #9

 P: n/a "rocio" schrieb How can I format a string like this: 12924.999999999999 to print 12,925 ? dim s as string = "12924.999999999999" dim d as decimal d = decimal.parse(s) s = d.tostring("#,##0") -- Armin http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html Nov 20 '05 #10

### This discussion thread is closed

Replies have been disabled for this discussion.