Results 1 to 2 of 2

Thread: work with formated numbers

  1. #1
    Chinavo is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Jul 2008
    Posts
    16
    Reputation
    62

    work with formated numbers

    Hi

    i have a listview where i want to show some numbers separated by '

    So the format will be like this:

    1'000'000.00

    So first i put the numbers to the listview by using a textbox. Later
    i need to take the numbers out and work on with them. But i can not calculate
    or do whatever with them in that format. so i'd like to know how to handle that the best way.

    Thanx for ur help

    chinavo

  2. #2
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,205
    Reputation
    2369
    Use the same CultureInfo/NumberFormatInfo you used to format the number to that string format to Parse it back to numeric data. Here's an example using a custom NumberFormatInfo (because that formatting differs from my default culture number formatting):
    Code:
    Dim nfi As New Globalization.NumberFormatInfo
    nfi.NumberDecimalSeparator = "."
    nfi.NumberGroupSeparator = "'"
    Dim d As Decimal = 1000
    Dim s As String = d.ToString("n2", nfi)
    d = Decimal.Parse(s, nfi)
    You can see how using the the current culture info will allow you to format numbers like user would like to see them wherever in the world, and parsing it back again.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking