473,324 Members | 1,856 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,324 software developers and data experts.

format a "numeric" string

How can I format a string like this: 12924.999999999999
to print 12,925 ?



Nov 20 '05 #1
9 4723
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.999999999999
to print 12,925 ?



.

Nov 20 '05 #2
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
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
yes, it works.

Tx!
"BeGomes" <be*****@hotmail.com> 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.999999999999
to print 12,925 ?



.

Nov 20 '05 #5
You can also just use

String.Format
"rocio" <ro************@softwareservices.net> 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
I 'Allways' f&*%£ng forget that

Regards - OHM
CJ Taylor wrote:
You can also just use

String.Format
"rocio" <ro************@softwareservices.net> 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
hehe I love string.format... If .NET gave me nothing else, it gave me
that... =)
"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> 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" <ro************@softwareservices.net> 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
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" <ro************@softwareservices.net> 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
"rocio" <ro************@softwareservices.net> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: BillCo | last post by:
I've been running a text-to-table import as part of a daily routine for years and I've just added a few new fields and updated the import spec. The strange thing is that it works perfectly when...
8
by: jchludzinski | last post by:
Is there a format specification for printf that will result in: 1000000 being printed as 1,000,000? Or 1000000.0 as 1,000,000.0? ---John
3
by: Mark | last post by:
I have a Decimal or a Double - your choice. I'd like to print the number as string with a specified number of decimal places. Let's say my number 110.5, and I'd like to capture it in a string...
6
by: Peter Afonin | last post by:
Hello, Should be a pretty simple question: I need to validate a string. It must be numeric and contain exactly 12 characters. I know how to do it in code, but I'd like to use a validation...
9
by: Bernie Yaeger | last post by:
I'm trying to control the textbox keypress event to deal with a "." such that it disallows a second "." and no characters after 2 numbers beyond the "." (thus a currency value). I have no problem...
1
by: Vera | last post by:
I have a problem formatting a string I have a decimal myDecimal which contains 0,3 What I want to display in a string is "€ 0,30" So here's what I do Dim myString As Strin Dim prov As...
0
by: rajmgopal | last post by:
Hello Everyone I am getting the following error when i try to insert a record into Sql Server 2005 from my VB 2005 application. sqlEx = {"Error converting data type numeric to numeric."} I...
2
by: jain_tj | last post by:
Could anyone please help me with the following problem My xml file is ============== <fig id="F0000001"> <caption>Caption text</caption> <image id="I0000001" image.class="halftone"...
3
by: tdickerson | last post by:
Hi, I'm encountering a strange error after an upgrade has been run on a test site. Attempting to SELECT * FROM table or even just entering SELECT * (no table specified) returns the following...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.