Problem with Numeric Formatting

Hi all.

I am trying to format the currencies in my app using thousands grouping and decimal separation.

I used the following class to do this:

[code]
Imports System
Imports System.Globalization

Public Class Globalizations

Public Shared nfi As NumberFormatInfo = New CultureInfo("el-GR", False).NumberFormat
Public Shared dtfi As DateTimeFormatInfo = New CultureInfo("el-GR", False).DateTimeFormat

End Class
[/code]

Then, in my form I used this code to format my number according to what I wanted it to look like:

[code]
Dim MyNum As Double = (Me.TextBox1.Text * Me.TextBox2.Text / 100)
Me.TextBox3.Text = MyNum.ToString("N", Globalizations.nfi)
[/code]

My problem is that this formatted number cannot participate in mathematical functions with the . symbol inside it as the thousands grouping symbol, but rather I have to use this command to make it usable:

[code]
Replace(Replace(Me.TextBox3, ".", ""), ",", ".")
[/code]

Is there any way to remove the formating without this double Replace command? Or maybe is there anything else I can do, to make the formatted number usable in mathematical functions, without it de-formatted?

Also, is there a way to assign the value to my control's text property and format it at the same time, without using the intermediate variable MyNum? I mean something like the following which I tried, but doesn't work:

[code]
Me.TextBox3.Text = (CDbl(Me.TextBox1.Text) + CDbl(Me.TextBox2.Text)).ToString("N", Globalizations.nfi)
[/code]

Thanks.

Comments

  • Cast the textbox value to a numeric value that's appropriate.

    You may also want to read the VB doc topic "formatNumber method"

    HTHs

    vbn
  • : Cast the textbox value to a numeric value that's appropriate.
    :
    : You may also want to read the VB doc topic "formatNumber method"
    :
    : HTHs
    :
    : vbn
    :
    [red]***************************************************************[/red]

    The easiest way to format it is:

    [blue]Imports[/blue] System.Convert


    Label.Text = Variable.ToString("$#,###.##")


  • Thanks

    I was not aware it was even that simple.

    Cheers
    vbn

  • Thank you very much. I didn't know this method. I haven't tried it yet, but I hope it works. Thanks again. Take care. Bye.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories