Converting string to currency/formatting in thousands.aspx (.NET)

Discussion in 'ASP .Net' started by pebelund, Oct 23, 2006.

  1. pebelund

    pebelund Guest

    Hi
    I got an .aspx that got the following code (example)

    <td width="120">
    <% = row["valueinString"] %>
    </td>

    row["string"] takes a value from a SQL db, that is a string of numbers.
    On the webbsite I want this to show as value formatted in thousands
    (example: I get the value 12345678, and I want it to show like 12 345
    678 OR even like, 12.345.678 (currency value).

    Anyone have an idea of how to make this happen? (newbeginner problem
    probably, but that is what I am so :p )

    Regards
    Peter
     
    pebelund, Oct 23, 2006
    #1
    1. Advertising

  2. On Mon, 23 Oct 2006 12:09:34 +0200, pebelund <> wrote:

    > Hi
    > I got an .aspx that got the following code (example)
    >
    > <td width="120">
    > <% = row["valueinString"] %>
    > </td>
    >
    > row["string"] takes a value from a SQL db, that is a string of numbers.
    > On the webbsite I want this to show as value formatted in thousands
    > (example: I get the value 12345678, and I want it to show like 12 345
    > 678 OR even like, 12.345.678 (currency value).
    >
    > Anyone have an idea of how to make this happen? (newbeginner problem
    > probably, but that is what I am so :p )
    >
    > Regards
    > Peter
    >


    Hi Peter,

    Would you be looking for the number format specifier in ToString(). Using
    C or c as the specifier would output the number as money, and using N or n
    would do the same without the currency symbol. The output is culture
    specific. If you don't want the default two decimals, use C#, c#, N#, n#
    where # is the number of decimals

    If you have a string 12345678 you would first need to parse it to an
    integer (or another number of your choice).

    string s = "12345678";
    int n = int.Parse(s);

    string output = n.ToString("c");

    output =
    $12,345,678.00 (en-US)
    £12,345,678.00 (en-GB)
    kr 12 345 678,00 (nb-NO)

    --
    Happy Coding!
    Morten Wennevik [C# MVP]
     
    Morten Wennevik, Oct 23, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    5
    Views:
    448
  2. Replies:
    6
    Views:
    1,606
  3. SimonPalmer
    Replies:
    3
    Views:
    478
    Fredrik Lundh
    Sep 7, 2008
  4. Barrie Jarman

    Formatting to "Thousands"

    Barrie Jarman, Feb 28, 2006, in forum: Ruby
    Replies:
    5
    Views:
    153
    Logan Capaldo
    Mar 1, 2006
  5. Douglas
    Replies:
    12
    Views:
    808
Loading...

Share This Page