Frustrated with Formatting

  • Thread starter Thread starter coleenholley
  • Start date Start date
C

coleenholley

I'm trying to format this bit of code into a numeric format of 12,123 no decimals in the particular format. Here's the code:

tbl_worksheet1.Rows(b).Cells(2).Text() = Format(ls_sum_gasohol, "##,##0")

This of course reurns a literal string of ##,##0 not the formatted number. I tried

= String.Format(ls_sum_gasohol, "##,##0") which returns me exactly what I had before, the number without the comma. How do I get the format to work correctly? I tried converting to an Integer, that doesn't work either. This SHOULD be simple. I've checked the help files on formatting, and found mystr = Format(itme, "##,##0") That is what I did and it ddoesn't work. Please help - formatting should be easy, not frustrating! TIA - Coleen
 
Never Mind - sorry. I figured it out. For those of you trying to do formatting I used:

Format(CInt(ls_sum_gasohol), "##,##0") This worked exactly like I wanted.

Unfortunately, the Help files do not give you this type of example anywhere that I could find. Using Help should be easier too!

Thanks - Coleen
 
Hi,

Try this.
Dim x As Integer = "12,123.65"

Me.Text = x.ToString("##,##0")

Ken
 
Thanks Ken - I did try using the x.ToString method, but I didn't get the results I wanted, so I used:

Format(CInt(itemtobeformatted), "##,##0")

it worked exactly as needed - except now I 'm having rounding problems with the one column I converted to a double Format(CDbl(item), "##,##0.00")

This doesn't seem to round correctly. I'm currently looking at the Help files on Rounding...not much for VB...any suggestions where to look? Thanks again :-) Coleen
 
coleenholley wrote in message news: said:
I'm trying to format this bit of code into a numeric format of 12,123 no decimals in the particular format. Here's the code:

tbl_worksheet1.Rows(b).Cells(2).Text() = Format(ls_sum_gasohol, "##,##0")

In this case the format function expects the expression to be a valid number.

Try Dim aString As String = "12345"
TextBox1.Text = Format(Int32.Parse(aString), "$#,##0")

Charlie
 
Hi Coleen,

Take a look at math.round

HTH,

Bernie Yaeger

Thanks Ken - I did try using the x.ToString method, but I didn't get the results I wanted, so I used:

Format(CInt(itemtobeformatted), "##,##0")

it worked exactly as needed - except now I 'm having rounding problems
with the one column I converted to a double Format(CDbl(item), "##,##0.00")
This doesn't seem to round correctly. I'm currently looking at the Help
files on Rounding...not much for VB...any suggestions where to look? Thanks
again :-) ColeenCommunity Website: http://www.dotnetjunkies.com/newsgroups/
 
Thanks Bernie - I did find that in the help files, but I am a little confused with the overlaod. If I have a number that has 5 places to the right of the decimal, and I want it to round how does the overload work? I need a number such as 62.33292 to round to 62.33, but if the number is 62.334999, I need it to round to 62.34. Does the rounding also depend on how I've formatted? Such as a format of ##, ##0.#0 seems to round to the tenth, but not always in the manner that I need. Any suggestions on the overlaod? Thanks :-) Coleen
 
Hi Coleen,

I'm not sure but it's easy enough to test both conditions. However, why
does .33292 become .33 but .334999 becomes .34? If it's because the back
end rounds to .5 and then .5 rounds up, you need only add something like
math.round() etc + .00005.

HTH,

Bernie
Thanks Bernie - I did find that in the help files, but I am a little
confused with the overlaod. If I have a number that has 5 places to the
right of the decimal, and I want it to round how does the overload work? I
need a number such as 62.33292 to round to 62.33, but if the number is
62.334999, I need it to round to 62.34. Does the rounding also depend on
how I've formatted? Such as a format of ##, ##0.#0 seems to round to the
tenth, but not always in the manner that I need. Any suggestions on the
overlaod? Thanks :-) ColeenCommunity Website: http://www.dotnetjunkies.com/newsgroups/
 
Hi Colleen,

That is the way as the vb.net rounding has to be done. You have the choise
from 1 method.
The behavior of this method follows IEEE Standard 754, section 4. This kind
of rounding is sometimes called rounding to nearest, or banker's rounding.

I do not know which countries are using this method, but definatly not mine
in local use.

But I am curious in which countries this is standard, so if someone sees
this can he tell if it is standard in his country.

Cor
 
Back
Top